• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Cancelling selection in JTree

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a user changes a selection in a tree and selects another node, I need to perform a validation. If not validated, I should cancel the selection of the new node and retain the selection on the old node.

Is there any way I can cancel a node selection that is made? I do not want to select back the old node because that would fire a node selection event again. I just want to cancel the selection and revert back to the old node.
 
Praveen Balaji
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's always orgasmic to come up with a solution to your posted question before a guru answers it. Here's what I figured out:

public class TreeTest extends JTree
{
public void setSelectionPath(TreePath path)
{
int option = JOptionPane.showConfirmDialog(null, "Change path?");
if(option == JOptionPane.YES_OPTION)
super.setSelectionPath(path);
}
}


Thanks for looking into it. Do let me know if there are alternative/better ways of doing this.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!