print out all the leaf nodes

Hi, Given that I already have a JTree, how can i print out all the names of the leaf nodes to console?Thanks in advanceregards
[154 byte] By [yiming1a] at [2007-10-2 10:14:15]
# 1

Given a tree model called 'treeModel' that is built from TreeNode elements then you can use

visitAllNodes((TreeNode)treeModel.getRoot());

using

private void visitAllNodes(TreeNode parent)

{

if (parent.isLeaf())

{

System.out.println(parent);

}

else

{

for (Enumeration e = parent.children(); e.hasMoreElements();)

{

visitAllNodes((TreeNode)e.nextElement());

}

}

}

sabre150a at 2007-7-13 1:37:44 > top of Java-index,Desktop,Core GUI APIs...