This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jtree - get/set previous selection  RSS feed

 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to revert the jtree node selection to it's previous selection when i see a flag set.
i.e, say node A is selected. User new selects node B while flag is true. I want the node selection to be reverted back so that node A is selected again.
I am using the following code in valueChanged() method of TreeSelectionListener class. but, this keeps calling itself and hence not a good code. any other way(s)?
JTree jtree = (JTree)event.getSource();
if(f_IsAddTempNode) {
TreePath oldPath = event.getOldLeadSelectionPath();
EuamDefaultMutableTreeNode node = (EuamDefaultMutableTreeNode)oldPath.getLastPathComponent();
setTreeSelection(jtree, node);
return;
}
Thanks.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
the simplest way would be to use a flag that tells you when you are adjusting the setting:

or you might use setValueIsAdjusting(boolean) of the selection model (in the same way as the setOldSelection flag is used). but you will have to try whether that works.
cheers
Chantal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!