Java JTree Expand expandTree(JTree tree, TreeNode start, int level)

Here you can find the source of expandTree(JTree tree, TreeNode start, int level)

Description

expand Tree

License

Open Source License

Parameter

Parameter Description
tree com.sun.java.swing.JTree
start com.sun.java.swing.tree.DefaultMutableTreeNode

Declaration

public static void expandTree(JTree tree, TreeNode start, int level) 

Method Source Code


//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;
    }
}

Related

  1. expandOrCollapseJTree(JTree tree, boolean expand)
  2. expandPath(JTree tree, TreePath tp)
  3. expandPathOnEdt(final JTree tree, final TreePath path)
  4. expandPaths(JTree tree, Collection paths)
  5. expandTree(JTree tree, boolean expand)
  6. expandTreeLevels(JTree tree, TreePath parent, boolean expand, int desiredLevel)
  7. expandTreePaths(JTree tree, Enumeration expandPaths)
  8. fullExpand(JTree tree, TreePath parentPath, int nExpansions)
  9. getExpandedPaths(JTree tree)