• Post Reply Bookmark Topic Watch Topic
  • New Topic

jtree nodes..how to disable it  RSS feed

 
aminur rashid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • 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
 
Bhagya Tangutur
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • 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[]);
}
}

}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!