Java JTree Expand expand(JTree tree, int level)

Here you can find the source of expand(JTree tree, int level)

Description

expand

License

Apache License

Declaration

public static void expand(JTree tree, int level) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.swing.JTree;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

public class Main {
    public static void expand(JTree tree, int level) {
        DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) tree.getModel().getRoot();
        while (currentNode != null) {
            if (currentNode.getLevel() <= level) {
                tree.expandPath(new TreePath(currentNode.getPath()));
            }// www .ja  va2 s .  c  om
            currentNode = currentNode.getNextNode();
        }
    }
}

Related

  1. autoExpand(JTree tree, TreePath path, int maxLines, int maxChildToExpand, boolean dontExpandToLeafs)
  2. buildTreePath(JTree tree, TreePath parent, String[] nodes, int startdepth, boolean expandable)
  3. expand(JTree tree, int depth)
  4. expand(JTree tree, int startingIndex, int rowCount)
  5. expandAll(final JTree tree, final TreePath parent, final boolean expand)
  6. expandAll(JTree jTree)
  7. expandAll(JTree rightTree)