Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Help on Searching a string in JTree

  Asked By: Cory    Date: Nov 26    Category: Java    Views: 1183
  

How can I search a specific string inside JTree node/children? I mean
when I input a word, the matched word will be hightlighted in the
JTree.

My code is as following, but it doens't search a string

private DefaultMutableTreeNode findUserObject( Object target ){
DefaultMutableTreeNode root =
(DefaultMutableTreeNode)fileTree.getModel().getRoot();
DefaultMutableTreeNode node = null;
if( root != null ){
for( Enumeration e = root.breadthFirstEnumeration(); e.hasMoreElements
(); )
{
DefaultMutableTreeNode current =
(DefaultMutableTreeNode)e.nextElement();

if( target.equals(current.getUserObject()) ){
node = current;
return node;
}
}
}
return null;
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Help on Searching a string in JTree Or get search suggestion and latest updates.




Tagged: