Swing/TreeNodeCollapseVeto のバックアップ(No.10)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/TreeNodeCollapseVeto へ行く。
- 1 (2014-11-09 (日) 02:54:09)
- 2 (2015-12-11 (金) 03:26:28)
- 3 (2017-06-01 (木) 11:11:23)
- 4 (2017-10-10 (火) 16:11:52)
- 5 (2019-04-15 (月) 16:05:54)
- 6 (2021-01-24 (日) 03:44:43)
- 7 (2023-09-15 (金) 12:47:00)
- 8 (2025-01-03 (金) 08:57:02)
- 9 (2025-01-03 (金) 09:01:23)
- 10 (2025-01-03 (金) 09:02:38)
- 11 (2025-01-03 (金) 09:03:21)
- 12 (2025-01-03 (金) 09:04:02)
- category: swing
folder: TreeNodeCollapseVeto
title: JTreeのノードを折り畳み不可に設定する
tags: [JTree]
author: aterai
pubdate: 2014-11-03T00:09:16+09:00
description: JTreeのノードをマウスでクリックしても折り畳まれないように設定します。
image:
Summary
JTree
のノードをマウスでクリックしても折り畳まれないように設定します。
Screenshot

Advertisement
Source Code Examples
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");
}
});
View in GitHub: Java, Kotlin解説
- 左: デフォルト
- 右: ノードの折り畳み不可
TreeWillExpandListener#treeWillCollapse()
メソッドをオーバーライドしてExpandVetoException
を発生させることでマウスやキー入力によるノードの折り畳みを不可に設定- ノードの展開、編集、選択などは可能