• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jtree - get/set previous selection

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic