rjopata
asked on
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.
how can i enumerate only nodes and not the entire tree.ie enumerating only interested nodes.
thanks.
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
have a look at here
http://javaalmanac.com/egs/javax.swing.tree/FindNode.html?l=rel
find the node then traverse
http://javaalmanac.com/egs/javax.swing.tree/FindNode.html?l=rel
find the node then traverse
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
Otherwise the only solution is suggested by the experts above of iterating and finding the node
ASKER
Thanks everyone for such useful comments and information.i guess i will have to check and get back soon.
regards.
regards.
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);
}
}
}
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.
objects,
zzynx already posted which has the code of visitAllNodes() except the if (node.isLeaf()) :)
zzynx already posted which has the code of visitAllNodes() except the if (node.isLeaf()) :)
typo,
zzynx already posted the link which has the code of visitAllNodes() except the if (node.isLeaf())
zzynx already posted the link which has the code of visitAllNodes() except the if (node.isLeaf())
> except the if (node.isLeaf()) :)
Was think thats what was meant by only enumerate nodes
Was think thats what was meant by only enumerate nodes
ASKER
> except the if (node.isLeaf())
thats right object.
easy everyone.:)
thanks a lot.
thats right object.
easy everyone.:)
thanks a lot.
ASKER
all comments were really useful.
thanks everybody.
thanks everybody.
Thanks for accepting