• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deselecting JTree nodes

 
Colleen Lynch
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
Thanks
 
kate damond
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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,
Cheers,
Kate
 
Colleen Lynch
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic