Swing/TreePaintLines のバックアップソース(No.9)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/TreePaintLines へ行く。
- 1 (2008-02-04 (月) 16:09:01)
- 2 (2008-03-18 (火) 14:34:52)
- 3 (2012-09-09 (日) 09:37:18)
- 4 (2013-08-02 (金) 20:57:26)
- 5 (2013-09-07 (土) 00:30:27)
- 6 (2014-11-25 (火) 03:03:31)
- 7 (2015-01-13 (火) 11:29:05)
- 8 (2015-05-21 (木) 19:41:15)
- 9 (2016-08-08 (月) 02:11:21)
- 10 (2017-10-03 (火) 13:52:29)
- 11 (2019-04-09 (火) 15:45:42)
- 12 (2021-01-15 (金) 11:48:11)
- 13 (2023-07-28 (金) 17:12:10)
--- title: JTreeの水平垂直線を表示しない tags: [JTree, UIManager] author: aterai pubdate: 2008-02-04T16:09:01+09:00 description: JTreeのアイコンを繋ぐ水平垂直線の表示の有無を切り替えます。 --- * 概要 [#summary] `JTree`のアイコンを繋ぐ水平垂直線の表示の有無を切り替えます。 #download(https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTWNxTrfYI/AAAAAAAAAo4/xS9RjkcNYYM/s800/TreePaintLines.png) * サンプルコード [#sourcecode] #code(link){{ final JTree tree = new JTree(); add(new JCheckBox(new AbstractAction("Tree.paintLines") { @Override public void actionPerformed(ActionEvent e) { if (((JCheckBox) e.getSource()).isSelected()) { UIManager.put("Tree.paintLines", Boolean.TRUE); } else { UIManager.put("Tree.paintLines", Boolean.FALSE); } SwingUtilities.updateComponentTreeUI(tree); // 左のJTreeだけ更新 } }), BorderLayout.NORTH); }} * 解説 [#explanation] 上記のサンプルでは、左の`JTree`の水平線などの表示を、`UIManager.put("Tree.paintLines", Boolean.FALSE);`で切り替えています(右は常に非表示)。 元々、線を表示しない`GTKLookAndFeel`などでは、`UIManager.put("Tree.paintLines", Boolean.TRUE);`としても線は描画されないようです。 複数の`JTree`の表示を個別に切り替えたい場合は、[https://community.oracle.com/thread/1367209 Hide horizontal and vertical lines in a JTree | Oracle Forums]で、Michael_Dunn さんが投稿(`2007/10/24 2:42`)したコードのように、`BasicTreeUI#paintHorizontalLine`メソッドなどをオーバーライドする方法もあります。 * 参考リンク [#reference] - [https://community.oracle.com/thread/1367209 Hide horizontal and vertical lines in a JTree | Oracle Forums] * コメント [#comment] #comment #comment