TITLE:JTreeの水平垂直線を表示しない
#navi(../)
#tags(JTree, UIManager)
RIGHT:Posted by &author(aterai); at 2008-02-04
* JTreeの水平垂直線を表示しない [#la642829]
``JTree``のアイコンを繋ぐ水平垂直線の表示の有無を切り替えます。

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

#ref(https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTWNxTrfYI/AAAAAAAAAo4/xS9RjkcNYYM/s800/TreePaintLines.png)

** サンプルコード [#a4057d44]
#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);
    }
    tree.updateUI(); // 左のJTreeだけ更新
    //SwingUtilities.updateComponentTreeUI(MainPanel.this);
  }
}), BorderLayout.NORTH);
}}

** 解説 [#d8a44352]
上記のサンプルでは、左の``JTree``の水平線などの表示を、``UIManager.put("Tree.paintLines", Boolean.FALSE);``で切り替えています(右は常に非表示)。

元々、線を表示しない``GTKLookAndFeel``などでは、``UIManager.put("Tree.paintLines", Boolean.TRUE);``としても線は描画されないようです。

複数の``JTree``の表示を個別に切り替えたい場合は、[https://forums.oracle.com/message/5774205 Hide horizontal and vertical lines in a JTree | Oracle Forums]で、Michael_Dunn さんが投稿(``2007/10/24 2:42``)したコードのように、``BasicTreeUI#paintHorizontalLine``メソッドなどをオーバーライドする方法もあります。

** 参考リンク [#ld863a92]
- [https://forums.oracle.com/message/5774205 Hide horizontal and vertical lines in a JTree | Oracle Forums]

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