• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JTreeの水平垂直線を表示しない
#navi(../)
*JTreeの水平垂直線を表示しない [#la642829]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2008-02-04~
更新日:&lastmod;
---
category: swing
folder: TreePaintLines
title: JTreeの水平垂直線を表示しない
tags: [JTree, UIManager]
author: aterai
pubdate: 2008-02-04T16:09:01+09:00
description: JTreeのアイコンを繋ぐ水平垂直線の表示の有無を切り替えます。
image: https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTWNxTrfYI/AAAAAAAAAo4/xS9RjkcNYYM/s800/TreePaintLines.png
---
* 概要 [#summary]
`JTree`のアイコンを繋ぐ水平垂直線の表示の有無を切り替えます。

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

**概要 [#a4543dc6]
JTreeのアイコンを繋ぐ水平垂直線の表示の有無を切り替えます。

#screenshot

**サンプルコード [#a4057d44]
#code{{
* サンプルコード [#sourcecode]
#code(link){{
final JTree tree = new JTree();
add(new JCheckBox(new AbstractAction("Tree.paintLines") {
  public void actionPerformed(ActionEvent e) {
    if(((JCheckBox)e.getSource()).isSelected()) {
  @Override public void actionPerformed(ActionEvent e) {
    if (((JCheckBox) e.getSource()).isSelected()) {
      UIManager.put("Tree.paintLines", Boolean.TRUE);
    }else{
    } else {
      UIManager.put("Tree.paintLines", Boolean.FALSE);
    }
    tree.updateUI(); // 左のJTreeだけ更新
    //SwingUtilities.updateComponentTreeUI(MainPanel.this);
    SwingUtilities.updateComponentTreeUI(tree); // 左のJTreeだけ更新
  }
}), BorderLayout.NORTH);
}}
-&jnlp;
-&jar;
-&zip;

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

複数のJTreeの表示を個別に切り替えたい場合は、[[Swing - Hide horizontal and vertical lines in a JTree>http://forum.java.sun.com/thread.jspa?threadID=5229120]]のように、BasicTreeUI#paintHorizontalLine メソッドなどをオーバーライドする方法もあります。
- 右の`JTree`は常に水平垂直線を非表示に設定
- デフォルトで線を表示しない`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(...)`メソッドなどをオーバーライドする方法がある

**参考リンク [#ld863a92]
-[[[[Swing - Hide horizontal and vertical lines in a JTree>http://forum.java.sun.com/thread.jspa?threadID=5229120]]]]
* 参考リンク [#reference]
- [https://community.oracle.com/thread/1367209 Hide horizontal and vertical lines in a JTree | Oracle Forums]
- [[JTreeのノード間の接続線のスタイルを変更する>Swing/TreeLineStyle]]

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