• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic