Swing/TreeNodeCollapseVeto のバックアップ差分(No.5)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/TreeNodeCollapseVeto へ行く。
- 追加された行はこの色です。
- 削除された行はこの色です。
---
category: swing
folder: TreeNodeCollapseVeto
title: JTreeのノードを折り畳み不可に設定する
tags: [JTree]
author: aterai
pubdate: 2014-11-03T00:09:16+09:00
description: JTreeのノードをマウスでクリックしても折り畳まれないように設定します。
image: https://lh3.googleusercontent.com/-lmIva1c-vxw/VFZHTSmTigI/AAAAAAAANo0/jeRoJW178as/s800/TreeNodeCollapseVeto.png
---
* 概要 [#summary]
`JTree`のノードをマウスでクリックしても折り畳まれないように設定します。
#download(https://lh3.googleusercontent.com/-lmIva1c-vxw/VFZHTSmTigI/AAAAAAAANo0/jeRoJW178as/s800/TreeNodeCollapseVeto.png)
* サンプルコード [#sourcecode]
#code(link){{
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException {
//throw new ExpandVetoException(e, "Tree expansion cancelled");
}
@Override public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException {
throw new ExpandVetoException(e, "Tree collapse cancelled");
}
});
}}
* 解説 [#explanation]
- 左: デフォルト
- 右: ノードの折り畳み不可
-- `TreeWillExpandListener#treeWillCollapse()`で、`ExpandVetoException`を発生させることで、マウスやキー入力によるノードの折り畳みを不可に設定
-- ノードの展開、編集、選択などは可能
* 参考リンク [#reference]
- [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/event/TreeWillExpandListener.html TreeWillExpandListener (Java Platform SE 8)]
- [[JTreeで展開不可のノードを設定する>Swing/PreventNodeExpanding]]
* コメント [#comment]
#comment
#comment