TITLE:Separatorのグラデーション
#navi(../)
*Separatorのグラデーション [#m51f3588]
Posted by [[terai]] at 2004-03-29

#contents

**概要 [#r715b34a]
グラデーションするセパレータを作ってみます。

-&jnlp;
-&jar;
-&zip;

#screenshot

**サンプルコード [#z73fe6d9]
#code{{
class GradientSeparator extends JComponent{
  private final Color bgc = UIManager.getColor("Panel.background");
  private final Color ssc = UIManager.getColor("Separator.shadow");
  private final Color shc = UIManager.getColor("Separator.highlight");
  public GradientSeparator() {
    super();
    setPreferredSize(new Dimension(100, 2));
    setBorder(null);
  }
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    int w = getWidth();
    g2.setPaint(new GradientPaint(0, 0, ssc, w, 0, bgc, true));
    g2.fillRect(0, 0, w, 1);
    g2.setPaint(new GradientPaint(0, 0, shc, w, 0, bgc, true));
    g2.fillRect(0, 1, w, 1);
  }
}
}}

**解説 [#u88fd1d8]
上記のサンプルでは下のJSeparatorの描画にGradientPaintを使用し、グラデーションさせています。

JSeparatorにsetBorder()すると、セパレータが見えなくなる場合があるのですこし注意が必要です。

//**参考リンク
**コメント [#x0186bae]
#comment