File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Deselecting JTree nodes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Deselecting JTree nodes" Watch "Deselecting JTree nodes" New topic

Deselecting JTree nodes

Colleen Lynch

Joined: Jun 18, 2001
Posts: 15
Upon selecting a node in my JTree, the UserObject is added to a vector. If a node is deselected, how can I find out what node it is? getLastSelectedPathComponent() returns null. Is there any other method I can use or event triggered when a node is deselected?
I would really appreciate your help!!
kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
Listen for treeSelection events. When the selction changes, you can get at at the old LeadSelection Path through the TreeSelectionEvent...

Which is the one just unselected.
Let me know if this needs more explanation,
Colleen Lynch

Joined: Jun 18, 2001
Posts: 15
Thanks for your reply.
I also got the path of the node selected by using the method of the TreeSelectionEvent class, isAddedPath. This returns false if the node was deselected.
I now have a new problem... Hopefuly someone will know a solution. Say for example I have 2 nodes in my tree selected, and then I select another without pressing the ctrl key, therefore removing the others that were previously selected. Is there a method that will give me the nodes currently selected?
I agree. Here's the link:
subject: Deselecting JTree nodes
It's not a secret anymore!