Swing:如何忽略取消选择事件? [英] Swing: how can I ignore deselection events?
问题描述
我的自定义组件由JPanel
中的三个JTree
组成.一次只能选择一个JTree
,因此我为每个添加了TreeSelectionListener
的对象调用了先前选择的JTree
上的clearSelection()
. (有关更多详细信息,请参见此处).
My custom component is composed of three JTree
s inside a JPanel
. Only one JTree
should be selected at a time, so I've added a TreeSelectionListener
to each of them that calls clearSelection()
on the previously selected JTree
. (See here for more details).
这很好,但是我需要防止TreeSelectionListener
.区分选择事件和取消选择事件的简单方法就绰绰有余了.
That works fine, but I need to prevent the TreeSelectionListener
s to trigger when a JTree
is deselected. A simple way to distinguish a selection event from a deselection one would be more than enough.
提前谢谢!
推荐答案
只需从树中获取当前选择,如果它为空,则返回.
Just get the current selection from the tree and if it's empty, return.
这篇关于Swing:如何忽略取消选择事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!