Java JTree Expand expandNodesAtLevel(int level, JTree tree, TreePath parent)

Here you can find the source of expandNodesAtLevel(int level, JTree tree, TreePath parent)

Description

expand Nodes At Level

License

BSD License

Declaration

static void expandNodesAtLevel(int level, JTree tree, TreePath parent) 

Method Source Code

//package com.java2s;
/*   TouchStone design platform is a software to design protocols for lab        *
 *   experiments. It is published under the terms of a BSD license               *
 *   (see details below)                                                         *
 *   Author: Caroline Appert (appert@lri.fr)                                     *
 *   Copyright (c) 2010 Caroline Appert and INRIA, France.                       *
 *   TouchStone design platform reuses parts of an early version which were      *
 *   programmed by Matthis Gilbert.                                              *
 *********************************************************************************/

import java.util.Enumeration;

import javax.swing.JTree;

import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

public class Main {
    static void expandNodesAtLevel(int level, JTree tree, TreePath parent) {
        if (level == 0)
            return;
        TreeNode node = (TreeNode) parent.getLastPathComponent();
        if (node.getChildCount() >= 0) {
            for (Enumeration<?> e = node.children(); e.hasMoreElements();) {
                TreeNode n = (TreeNode) e.nextElement();
                TreePath path = parent.pathByAddingChild(n);
                tree.expandPath(path);//from ww  w.  jav  a 2 s .co  m
                expandNodesAtLevel(level - 1, tree, path);
            }
        }
    }
}

Related

  1. expandFirstNode(JTree tree)
  2. expandFirstNodeAtLevel(int level, JTree tree)
  3. expandFully(JTree tree, TreePath path)
  4. expandJTreeNode(javax.swing.JTree tree, javax.swing.tree.TreeModel model, Object node, int row, int depth)
  5. expandLevels(JTree tree, int levels, boolean expand)
  6. expandOrCollapseAllRows(final JTree tree, final boolean expand)
  7. expandOrCollapseJTree(JTree tree, boolean expand)
  8. expandPath(JTree tree, TreePath tp)
  9. expandPathOnEdt(final JTree tree, final TreePath path)