Here you can find the source of expandTree(JTree tree, TreeNode start, int level)
Parameter | Description |
---|---|
tree | com.sun.java.swing.JTree |
start | com.sun.java.swing.tree.DefaultMutableTreeNode |
public static void expandTree(JTree tree, TreeNode start, int level)
//package com.java2s; //License from project: Open Source License import java.util.Enumeration; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; public class Main { /**//www .j a v a2 s .c om * @param tree com.sun.java.swing.JTree * @param start com.sun.java.swing.tree.DefaultMutableTreeNode */ public static void expandTree(JTree tree, TreeNode start, int level) { for (Enumeration children = start.children(); children.hasMoreElements();) { DefaultMutableTreeNode dtm = (DefaultMutableTreeNode) children.nextElement(); //System.out.println(dtm.getUserObject()+" "+dtm.getDepth()); if (!dtm.isLeaf() && dtm.getLevel() <= level) { // TreePath tp = new TreePath(dtm.getPath()); tree.expandPath(tp); // expandTree(tree, dtm, level); } } return; } public static String getPath(Object[] str) { String res = ""; for (int i = 0; i < str.length; i++) { res += str[i].toString() + (i == 0 || i == str.length ? "" : "/"); } return res; } }