本文共 687 字,大约阅读时间需要 2 分钟。
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) { Enumerationchildren = node.children(); while (children.hasMoreElements()) { TreeNode n = children.nextElement(); TreePath newPath = path.pathByAddingChild(n); expandTree(tree, newPath); } } tree.expandPath(path); }}
转载地址:http://vsnws.baihongyu.com/