[ Back | Previous | Next ]

How to expand a whole tree programmatically?

Package:
javax.swing.tree.*
Product:
Swing
Release:
1.1.x
Related Links:
DefaultTreeModel
JTree
Comment:
Call this static method and it will happen.
/** * @param tree com.sun.java.swing.JTree * @param start com.sun.java.swing.tree.DefaultMutableTreeNode */ private static void expandTree(JTree tree, DefaultMutableTreeNode start) { for (Enumeration children = start.children(); children.hasMoreElements();) { DefaultMutableTreeNode dtm = (DefaultMutableTreeNode) children.nextElement(); if (!dtm.isLeaf()) { // TreePath tp = new TreePath( dtm.getPath() ); tree.expandPath(tp); // expandTree(tree, dtm); } } return; }
1