File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Breaking a  JTree Traversal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Breaking a  JTree Traversal" Watch "Breaking a  JTree Traversal" New topic
Author

Breaking a JTree Traversal

Casen Densmore
Greenhorn

Joined: Jan 22, 2004
Posts: 14
I am running a traversal of a JTree trying to find a certain node. When I do find that node I want to return true, indicating that I did in fact find it. The code below always returns false indicating to me that even though I return true when the item is found the loop continues to run.



Here is the print out of the test code.
Match Found!
No Match Found 1
No Match Found 1
false <------- a printout from what is returned.

Any ideas?
Thanks,
Casen
Casen Densmore
Greenhorn

Joined: Jan 22, 2004
Posts: 14
Ok, I see why it isn't working. I am calling multiple instance of the method therefore it would return a value for each one of them; the last one being false.

The question still remains, how can I manipulate the code so that once a match is found it would return true and stop the recursion?

Thanks,
Casen
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
You are ignoring the return value of the recursive call to traverse().


bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Breaking a JTree Traversal
 
Similar Threads
Select a node in Jtree
JCheckBox in Jtree Problem
Checkbox with Jtree
need help with jTree isNodeAncestor()
Subtree in JTree