Swing/TreeNodeCollapseVeto のバックアップソース(No.1)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/TreeNodeCollapseVeto へ行く。
--- title: JTreeのノードを折り畳み不可に設定する tags: [JTree] author: aterai pubdate: 2014-11-03T00:09:16+09:00 description: JTreeのノードをマウスでクリックしても折り畳まれないように設定します。 --- * 概要 [#p6725d02] `JTree`のノードをマウスでクリックしても折り畳まれないように設定します。 #download(https://lh3.googleusercontent.com/-lmIva1c-vxw/VFZHTSmTigI/AAAAAAAANo0/jeRoJW178as/s800/TreeNodeCollapseVeto.png) * サンプルコード [#a526a403] #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"); } }); }} * 解説 [#e113ea49] - 左: デフォルト - 右: ノードを折り畳み不可 -- `TreeWillExpandListener#treeWillCollapse()`で、`ExpandVetoException`を発生させることで、マウスやキー入力による折り畳みを不可に設定 -- ノードの展開、移動、編集、選択などは可能 * 参考リンク [#u6042dab] - [[JTreeで展開不可のノードを設定する>Swing/PreventNodeExpanding]] * コメント [#b99e4c02] #comment #comment