0

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!

1 Answer 1

2

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

1
  • Just as simple as "if (selectedTree.getSelectionCount() != 0)". I must admit I feel a little bit stupid :D Thanks!
    – Giuseppe
    Sep 23, 2009 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.