Swing/DashedLine のバックアップソース(No.23)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/DashedLine へ行く。
- 1 (2004-10-04 (月) 03:54:35)
- 2 (2004-10-04 (月) 03:54:57)
- 3 (2004-10-05 (火) 07:23:53)
- 4 (2004-10-08 (金) 06:18:23)
- 5 (2004-11-04 (木) 10:03:35)
- 6 (2005-04-28 (木) 04:33:04)
- 7 (2005-10-18 (火) 10:52:37)
- 8 (2006-02-27 (月) 15:37:35)
- 9 (2006-04-12 (水) 19:39:47)
- 10 (2006-05-12 (金) 10:44:23)
- 11 (2007-05-29 (火) 14:18:04)
- 12 (2007-08-16 (木) 17:19:05)
- 13 (2009-02-27 (金) 16:20:14)
- 14 (2011-05-05 (木) 08:28:21)
- 15 (2013-04-13 (土) 04:27:34)
- 16 (2013-09-15 (日) 00:17:36)
- 17 (2013-09-18 (水) 20:59:28)
- 18 (2014-11-11 (火) 19:44:26)
- 19 (2015-11-25 (水) 21:49:01)
- 20 (2017-04-04 (火) 14:17:08)
- 21 (2017-05-17 (水) 09:20:02)
- 22 (2018-05-01 (火) 21:14:02)
- 23 (2020-04-24 (金) 18:36:05)
- 24 (2021-10-27 (水) 00:02:51)
--- category: swing folder: DashedLine title: BasicStrokeで点線を作成 tags: [BasicStroke, Graphics2D] author: aterai pubdate: 2004-10-04T03:54:35+09:00 description: 破線パターンの配列からBasicStrokeを作成し、これを描画します。 image: https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTKaxPM12I/AAAAAAAAAV8/ZQON-woHuIg/s800/DashedLine.png --- * 概要 [#summary] 破線パターンの配列から`BasicStroke`を作成し、これを描画します。 #download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTKaxPM12I/AAAAAAAAAV8/ZQON-woHuIg/s800/DashedLine.png) * サンプルコード [#sourcecode] #code(link){{ JLabel label = new JLabel() { BasicStroke dashedStroke; @Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (dashedStroke == null) { dashedStroke = new BasicStroke( 5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, getDashArray(), 0f); } Insets i = getInsets(); int w = getWidth(); int h = getHeight() / 2; Graphics2D g2 = (Graphics2D) g.create(); g2.setStroke(dashedStroke); g2.drawLine(i.left, h, w - i.right, h); g2.dispose(); } }; }} * 解説 [#explanation] `BasicStroke`の破線属性を指定して点線をコンポーネント内に描画します。 上記のサンプルでは、カンマ区切りで記入した数値を配列に分解し、これを破線のパターンとして`BasicStroke`に渡しています。 * 参考リンク [#reference] - [https://docs.oracle.com/javase/jp/8/docs/api/java/awt/BasicStroke.html BasicStroke (Java Platform SE 8)] - [https://docs.oracle.com/javase/tutorial/2d/geometry/strokeandfill.html Stroking and Filling Graphics Primitives (The Java™ Tutorials > 2D Graphics > Working with Geometry)] * コメント [#comment] #comment #comment