Jtree Enumeration

i have a Jtree of 3 levels (root and three other nodes).
how can i enumerate only nodes and not the entire tree.ie enumerating only interested nodes.
thanks.
rjopataAsked:
Who is Participating?
 
zzynxConnect With a Mentor Software engineerCommented:
You traverse the whole tree (see http://javaalmanac.com/egs/javax.swing.tree/GetNodes.html) and
pick out the nodes that you're interested in
0
 
girionisCommented:
I am afraid you will have to enumerate through all of them and select the ones you want. What exactly are you trying to do?
0
 
expertmbCommented:
have  a look at here
http://javaalmanac.com/egs/javax.swing.tree/FindNode.html?l=rel

find the node then traverse
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
armoghanCommented:
What yuo can do is, while inserting the nodes, you can place them in some collection, ArrayList or HashTable and use them afterwards,
Otherwise the only solution is suggested by the experts above of iterating and finding the node
0
 
rjopataAuthor Commented:
Thanks everyone for such useful comments and information.i guess i will have to check and get back soon.
regards.
0
 
objectsCommented:

    public void visitAllNodes(TreeNode node) {
        // node is visited exactly once
        if (node.isLeaf()) {

           // a leaf node, do as you require

        }  else if (node.getChildCount() >= 0) {
            for (Enumeration e=node.children(); e.hasMoreElements(); ) {
                TreeNode n = (TreeNode)e.nextElement();
                visitAllNodes(n);
            }
        }
    }
0
 
objectsCommented:
If you're using DefaultMutableTreeNode then it has methods for returning Enumerations for all nodes which you can use to enumerate thru to find the leaf nodes.
0
 
expertmbCommented:
objects,
zzynx already posted which has the code of visitAllNodes() except the if (node.isLeaf()) :)
0
 
expertmbCommented:
typo,
zzynx already posted the link  which has the code of visitAllNodes() except the if (node.isLeaf())
0
 
objectsCommented:
> except the if (node.isLeaf()) :)

Was think thats what was meant by only enumerate nodes
0
 
rjopataAuthor Commented:
> except the if (node.isLeaf())
thats right object.
easy everyone.:)
thanks a lot.
0
 
rjopataAuthor Commented:
all comments were really useful.
thanks everybody.
0
 
zzynxSoftware engineerCommented:
Thanks for accepting
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.