Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Cancelling selection in JTree

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It's never done THAT before. Explain it to me tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic