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

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

http://terai.xrea.jp/swing/gradient/screenshot.png

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

-[[サンプルを起動>http://terai.xrea.jp/swing/gradient/sample.jnlp]]
-[[jarファイル>http://terai.xrea.jp/swing/gradient/sample.jar]]
-[[ソース>http://terai.xrea.jp/swing/gradient/src.zip]]
**解説 [#u88fd1d8]
GradientPaintを使ってJSeparatorをグラデーションしています。JSeparatorにsetBorder()すると、セパレータが見えなくなる場合があるのですこし注意が必要です。

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