Java JTree Expand expandAllNodes(JTree tree, TreeNode node)

Here you can find the source of expandAllNodes(JTree tree, TreeNode node)

Description

expands all nodes in the tree that descend from node

License

Open Source License

Parameter

Parameter Description
tree a parameter
node a parameter

Declaration

private static void expandAllNodes(JTree tree, TreeNode node) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import javax.swing.*;
import javax.swing.tree.*;

public class Main {
    /**/*from  www.j  a  v a2s. c o m*/
     * expands all nodes in the <code>tree</code>
     * @param tree
     * @precondition tree != null
     */
    public static void expandAllNodes(JTree tree) {
        expandAllNodes(tree, (TreeNode) tree.getModel().getRoot());
    }

    /**
     * expands all nodes in the <code>tree</code> that descend from <code>node</code>
     * @param tree
     * @param node
     */
    private static void expandAllNodes(JTree tree, TreeNode node) {
        final TreePath treepath = new TreePath(((DefaultMutableTreeNode) node).getPath());
        tree.expandPath(treepath);

        for (int i = 0; i < node.getChildCount(); i++) {
            expandAllNodes(tree, node.getChildAt(i));
        }
    }
}

Related

  1. expandAllNodes(final JTree tree)
  2. expandAllNodes(JTree tree)
  3. expandAllNodes(JTree tree)
  4. expandAllNodes(JTree tree, int startingIndex, int rowCount)
  5. expandAllNodes(JTree tree, int startingIndex, int rowCount)
  6. expandByExpansionStateStrings(final JTree tree, final TreePath parent, ArrayList expansionStateStrings)
  7. expandFirstNode(JTree tree)
  8. expandFirstNodeAtLevel(int level, JTree tree)
  9. expandFully(JTree tree, TreePath path)