<font size =5><pre>!_NEWLINE_!Searching a JTree with a String!_NEWLINE_!</pre></font>
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   surya_teja
Posted On:   Friday, February 8, 2002 03:19 AM

			

hi guys!


i am searching a JTree with
a "string"

now i want to go the specific node
(all expanded)

by matching the string to the node


how do i do it?



thank u

Srinivas

The node can be found as followes do you want to expand ,particular node then its here

Posted By:   Anonymous  
Posted On:   Friday, February 8, 2002 08:33 PM

Hai Srinivas
Try this it will work ,the tree object should be declared globaly
//public declaration
//JTree tree;
//DefaultTreeModel treeModel;

void expandTree(String str) {
DefaultMutableTreeNode rootNode=(DefaultMutableTreeNode)treeModel.getRoot();

Enumeration e = rootNode.breadthFirstEnumeration();

DefaultMutableTreeNode target=null;

while(e.hasMoreElements()){
target=null;
target=DefaultMutableTreeNode)e.nextElement();
String compStr=target.toString();

if(compStr.equals(str)){
TreePath path = new TreePath(((DefaultMutableTreeNode) target).getPath());
tree.makeVisible(path);
tree.setSelectionRow(tree.getRowForPath(path));
tree.scrollPathToVisible(path);
return;
}
}
}

If u face any problem contact rajeshspr@yahoo.com
About | Sitemap | Contact