Giuseppe
Giuseppe

Reputation: 357

Swing: how can I ignore deselection events?

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).

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.

Thanks in advance!

Upvotes: 0

Views: 420

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328604

Just get the current selection from the tree and if it's empty, return.

Upvotes: 2

Related Questions