Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Jtree Enumeration

Posted on 2004-09-13
13
Medium Priority
?
675 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

688 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