Swing:如何忽略取消选择事件? [英] Swing: how can I ignore deselection events?

查看:141
本文介绍了Swing:如何忽略取消选择事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的自定义组件由JPanel中的三个JTree组成.一次只能选择一个JTree,因此我为每个添加了TreeSelectionListener的对象调用了先前选择的JTree上的clearSelection(). (有关更多详细信息,请参见此处).

My custom component is composed of three JTrees 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 TreeSelectionListeners 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆