There is JTree component that I want to fill from the database. New nodes can be dynamically added to this tree. I need a procedure that will recursively traverse a tree. My problem is that only second-level nodes are added to the root node, but other-level nodes are not created. I've included System.out.println to see the results and problems. Please, help me to fix the error. Below is my code:
I would just call either the breadthFirstEnumeration() or the depthFirstEnumeration() method of the DefaultMutableTreeNode which is the root of the tree, if I wanted to traverse all the nodes of the tree model. I wouldn't bother to write my own code.
But what I actually do is to have the user object contain a link to the node which contains it. That way there's no searching required at all.
Joined: Aug 24, 2010
Well, probably my question is a bit unclear. I want to ADD nodes to the JTree, and not only search them.
Initially, I have a data set stored in the database and a BLANK JTree. This data set contains a tree structure, e.g.:
What I need, is to build the JTree based on the above-shown information.
So, does the depthFirstEnumeration() method of the DefaultMutableTreeNode provides possibilities to ADD nodes?