• 追加された行はこの色です。
  • 削除された行はこの色です。
#navi(../)
*BasicStrokeで点線を作成 [#w2f78e6a]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2004-10-04~
更新日:&lastmod;

#contents

**概要 [#l979ab53]
点線・破線を描画します。

http://terai.xrea.jp/swing/dashedline/screenshot.png
#screenshot

**サンプルコード [#r8083614]
 JLabel label = new JLabel() {
   BasicStroke dashed2 = new BasicStroke();
   public void paintComponent(Graphics g) {
     Graphics2D g2 = (Graphics2D)g;
     super.paintComponent(g2);
     if(flag) dashed2 = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
                   icStroke.JOIN_MITER, 10.0f, getDashArray(), 0.0f);
     flag = false;
     g2.setStroke(dashed2);
     g2.drawLine(5, getHeight()/2, getWidth()-10, getHeight()/2);
   }
 };

-[[サンプルを起動>http://terai.xrea.jp/swing/dashedline/sample.jnlp]]
-[[jarファイル>http://terai.xrea.jp/swing/dashedline/sample.jar]]
-[[ソース>http://terai.xrea.jp/swing/dashedline/src.zip]]
-&jnlp;
-&jar;
-&zip;

**解説 [#o6e7c935]
BasicStrokeの破線属性を指定して点線を描画します。

上記のサンプルでは、カンマ区切りで記入した数値を配列に分解し、これを破線のパターンとしてBasicStrokeに渡しています。

**参考リンク [#q0fcc75d]
-[[Stroking and Filling Graphics Primitives>http://java.sun.com/docs/books/tutorial/2d/display/strokeandfill.html]]

**コメント [#u22a4451]
#comment