TITLE:BasicStrokeで点線を作成
#navi(../)
#tags(BasicStroke, Graphics2D)
RIGHT:Posted by &author(aterai); at 2004-10-04
* BasicStrokeで点線を作成 [#w2f78e6a]
点線・破線を描画します。

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

#ref(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTKaxPM12I/AAAAAAAAAV8/ZQON-woHuIg/s800/DashedLine.png)

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

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

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

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

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