使用方法:SwingUtil.expandTree(tree);
public class SwingUtil {
public static void expandTree(JTree tree) {
TreeNode root = (TreeNode) tree.getModel().getRoot();
expandTree(tree, new TreePath(root));
}
public static void expandTree(JTree tree, TreePath path) {
TreeNode node = (TreeNode) path.getLastPathComponent();
// Go to leaf
if (node.getChildCount() > 0) {
Enumeration<TreeNode> children = node.children();
while (children.hasMoreElements()) {
TreeNode n = children.nextElement();
TreePath newPath = path.pathByAddingChild(n);
expandTree(tree, newPath);
}
}
tree.expandPath(path);
}
}
@import url(http://www.cppblog.com/cutesoft_client/cuteeditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);