Java JTree Node expandAll(JTree tree, DefaultMutableTreeNode root)

Here you can find the source of expandAll(JTree tree, DefaultMutableTreeNode root)

Description

Expand all the children nodes of the specified TreeNode.

License

Open Source License

Parameter

Parameter Description
tree the JTree containing the TreeNodes
root the TreeNode to expand the children

Declaration

public static void expandAll(JTree tree, DefaultMutableTreeNode root) 

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.TreePath;

public class Main {
    /**/*from   w  ww  .ja va  2s. c  o  m*/
     * Expand all the children nodes of the specified TreeNode.
     *
     * @param tree the JTree containing the TreeNodes
     * @param root the TreeNode to expand the children
     */
    public static void expandAll(JTree tree, DefaultMutableTreeNode root) {

        Enumeration<?> nodes = root.children();
        while (nodes.hasMoreElements()) {

            Object node = nodes.nextElement();
            if (node instanceof DefaultMutableTreeNode) {

                TreePath path = new TreePath(((DefaultMutableTreeNode) node).getPath());
                if (!tree.isExpanded(path)) {
                    tree.expandPath(path);
                }
            }
        }
    }
}

Related

  1. collapseSubTree(JTree tree, DefaultMutableTreeNode startNode, DefaultTreeModel model)
  2. contains(final JTree tree, final TreeNode node)
  3. copyDMTreeNode(DefaultMutableTreeNode out, DefaultMutableTreeNode in)
  4. createFolderNode(Object userObject)
  5. createSubTreeIfNecessary(TreeModel model, DefaultMutableTreeNode parent, String childName)
  6. expandAll(JTree tree, DefaultMutableTreeNode treeNode)
  7. expandEntireTree(JTree tree, DefaultMutableTreeNode root, boolean expandRoot)
  8. expandPathsAfterChange(JTree tree, Hashtable state, DefaultMutableTreeNode root)
  9. expandTree(final JTree tree, final DefaultMutableTreeNode node)