Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Jtree Enumeration

Posted on 2004-09-13
13
Medium Priority
?
679 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

972 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