Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cancelling selection in JTree  RSS feed

 
Praveen Balaji
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!