Swing/TreeClearSelection のバックアップ差分(No.9)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/TreeClearSelection へ行く。
- 1 (2010-12-06 (月) 14:44:47)
- 2 (2010-12-06 (月) 18:11:37)
- 3 (2010-12-17 (金) 21:19:12)
- 4 (2010-12-18 (土) 02:55:07)
- 5 (2012-12-25 (火) 11:25:26)
- 6 (2013-10-11 (金) 12:53:36)
- 7 (2015-02-05 (木) 14:41:21)
- 8 (2016-09-10 (土) 23:43:03)
- 9 (2017-10-25 (水) 15:44:05)
- 10 (2019-04-01 (月) 18:17:21)
- 11 (2019-10-28 (月) 20:49:57)
- 12 (2021-05-22 (土) 04:40:38)
- 追加された行はこの色です。
- 削除された行はこの色です。
--- category: swing folder: TreeClearSelection title: JTreeの選択状態を解除する tags: [JTree, MouseListener] author: aterai pubdate: 2010-12-06T14:44:47+09:00 description: JTreeでノード以外の領域をマウスでクリックした場合、選択状態を解除します。 image: https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTWDzni-uI/AAAAAAAAAoo/r6UW4JENwgI/s800/TreeClearSelection.png --- * 概要 [#summary] `JTree`でノード以外の領域をマウスでクリックした場合、選択状態を解除します。 #download(https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTWDzni-uI/AAAAAAAAAoo/r6UW4JENwgI/s800/TreeClearSelection.png) * サンプルコード [#sourcecode] #code(link){{ tree.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { JTree tree = (JTree) e.getComponent(); if (tree.getRowForLocation(e.getX(), e.getY()) < 0) { tree.clearSelection(); } } }); }} * 解説 [#explanation] 上記のサンプルでは、`JTree#getRowForLocation(...)`メソッドを使用して、`JTree`のノード以外のポイントがクリックされたかどうかを判断しています。ノードの選択解除自体は、`JTree#clearSelection()`が使用できます。 上記のサンプルでは、`JTree#getRowForLocation(...)`メソッドを使用して、`JTree`のノード以外の場所がクリックされたかどうかを判断しています。ノードの選択解除自体は、`JTree#clearSelection()`を使用しています。 * 参考リンク [#reference] - [http://docs.oracle.com/javase/jp/6/api/javax/swing/JTree.html JTree (Java Platform SE 6)]のサンプルコード * コメント [#comment] #comment #comment