Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 681
  • Last Modified:

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.
0
rjopata
Asked:
rjopata
  • 3
  • 3
  • 3
  • +3
1 Solution
 
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
 
zzynxSoftware 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
 
expertmbCommented:
have  a look at here
http://javaalmanac.com/egs/javax.swing.tree/FindNode.html?l=rel

find the node then traverse
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now