Java JTree Node expandEntireTree(JTree tree, DefaultMutableTreeNode root, boolean expandRoot)

Here you can find the source of expandEntireTree(JTree tree, DefaultMutableTreeNode root, boolean expandRoot)

Description

expand Entire Tree

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static void expandEntireTree(JTree tree, DefaultMutableTreeNode root, boolean expandRoot) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) JavaPEG developers/*from  w  w w . java2 s  .c o m*/
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

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

import javax.swing.tree.TreePath;
import java.util.*;

public class Main {
    @SuppressWarnings("unchecked")
    public static void expandEntireTree(JTree tree, DefaultMutableTreeNode root, boolean expandRoot) {

        if (expandRoot) {
            tree.expandPath(new TreePath(root.getPath()));
        }

        Enumeration<DefaultMutableTreeNode> children = root.children();

        while (children.hasMoreElements()) {
            DefaultMutableTreeNode child = children.nextElement();

            tree.expandPath(new TreePath(child.getPath()));

            if (child.children().hasMoreElements()) {
                expandEntireTree(tree, child, expandRoot);
            }
        }
    }
}

Related

  1. copyDMTreeNode(DefaultMutableTreeNode out, DefaultMutableTreeNode in)
  2. createFolderNode(Object userObject)
  3. createSubTreeIfNecessary(TreeModel model, DefaultMutableTreeNode parent, String childName)
  4. expandAll(JTree tree, DefaultMutableTreeNode root)
  5. expandAll(JTree tree, DefaultMutableTreeNode treeNode)
  6. expandPathsAfterChange(JTree tree, Hashtable state, DefaultMutableTreeNode root)
  7. expandTree(final JTree tree, final DefaultMutableTreeNode node)
  8. expandTreeRecurser(JTree tree, DefaultMutableTreeNode node)
  9. export(File file, DefaultMutableTreeNode node)