rkcole.com
Here is a simple recursive method for traversing a JTree and printing all the leaf nodes (originally posted to comp.lang.java.programmer, November 2000)
.
.
TreeModel model = tree.getModel();
Object root = model.getRoot();
walk( model, root );
.
.
/**
* Visit every node in the tree and print the leaf nodes.
* @param model the JTree's model
* @param o Start at this branch in the tree.
*/
protected void walk( TreeModel model, Object o )
{
int count = model.getChildCount(o);
for( int i=0; i < count; i++ )
{
Object child = model.getChild(o, i );
if ( model.isLeaf( child ) )
System.out.println( child.toString() );
else
walk( model, child );
}
}