• 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 nodes..how to disable it

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a Jtree and I want to prevent user selecting some nodes of this tree.I did this by adding a TreeSelectionListner to the tree and then in the value changed method of this listner ,I checked the current node is the node that I dont want user to select,I used the method removeSelectionPath(TreePath tp).

In my approach what i am doing is first allowing the user to select the node and then removing the selection from node.
Is there any method to prevent the user from selcting a node at the inital state only by using the TreeSelectionModel.
Help is needed
A
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try overriding canPathsBeAddedMethod(TreePath[]).it looks like they are checking each time before they do tree selection on tree.
the may be similar to this...
assuming you have some string information{"a","b","c","d"} or some objects{a1,a2,a3}.
i haven't put down the code completely ...i guess ,it is understandable.
protected boolean canPathsBeSelected(TreePath paths[]){
for(int i=0;i<paths.length;i++){
if(paths[i].getObject().equals(one of u r objects) ||paths[i].getObject().getName().equals(one of your Strings)){
return false;
}else{
return super.canPathsBeSelected(paths[]);
}
}

}
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic