Solved

Jtree Enumeration

Posted on 2004-09-13
13
657 Views
Last Modified: 2012-05-05
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
Comment
Question by:rjopata
  • 3
  • 3
  • 3
  • +3
13 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 12051840
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
 
LVL 37

Accepted Solution

by:
zzynx earned 50 total points
ID: 12051843
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
 
LVL 6

Expert Comment

by:expertmb
ID: 12051847
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!

 
LVL 18

Expert Comment

by:armoghan
ID: 12051880
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
 

Author Comment

by:rjopata
ID: 12051908
Thanks everyone for such useful comments and information.i guess i will have to check and get back soon.
regards.
0
 
LVL 92

Expert Comment

by:objects
ID: 12051912

    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
 
LVL 92

Expert Comment

by:objects
ID: 12051919
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
 
LVL 6

Expert Comment

by:expertmb
ID: 12051935
objects,
zzynx already posted which has the code of visitAllNodes() except the if (node.isLeaf()) :)
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12051940
typo,
zzynx already posted the link  which has the code of visitAllNodes() except the if (node.isLeaf())
0
 
LVL 92

Expert Comment

by:objects
ID: 12051956
> except the if (node.isLeaf()) :)

Was think thats what was meant by only enumerate nodes
0
 

Author Comment

by:rjopata
ID: 12052050
> except the if (node.isLeaf())
thats right object.
easy everyone.:)
thanks a lot.
0
 

Author Comment

by:rjopata
ID: 12057979
all comments were really useful.
thanks everybody.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12061775
Thanks for accepting
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues undeā€¦
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question