TITLE:Separatorのグラデーション
#navi(../)
*Separatorのグラデーション [#m51f3588]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2004-03-29~
更新日:&lastmod;

#contents

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

#screenshot

**サンプルコード [#z73fe6d9]
 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);
   }
 }

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

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

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

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