#navi(contents-page-name): No such page: ST

FrontPage>Swing Tips>ST/Gradient

ST/Gradient

Terai Atsuhiro 2022-01-14 (金) 07:56:54

http://terai.s55.xrea.com/swing/gradient/screenshot.png

class GradientSeparator extends JComponent{
  public GradientSeparator(){
    super();
    setPreferredSize(new Dimension(100, 2));
    setBorder(null);
  }
  protected void paintComponent(Graphics g){
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    Insets ins = getInsets();
    g2.setPaint(new GradientPaint(0, 0, SystemColor.controlShadow,
                                  getWidth(), 0, SystemColor.control, false));
    g2.fillRect(0, 0, getWidth(), 1);
    g2.setPaint(new GradientPaint(0, 0, SystemColor.controlLtHighlight,
                                  getWidth(), 0, SystemColor.control, false));
    g2.fillRect(0, 1, getWidth(), 1);
  }
}