Java JTree Expand expandAll(JTree tree, boolean expand)

Here you can find the source of expandAll(JTree tree, boolean expand)

Description

expand All

License

Open Source License

Declaration

public static void expandAll(JTree tree, boolean expand) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static void expandAll(JTree tree, boolean expand) {
        TreeNode root = (TreeNode) tree.getModel().getRoot();
        expandAll(tree, new TreePath(root), expand);
    }//from  ww w.j a  v a2s . c  o m

    public static void expandAll(JTree tree, TreePath parent, boolean expand) {
        TreeNode node = (TreeNode) parent.getLastPathComponent();
        if (node.getChildCount() >= 0) {
            for (int i = 0; i < node.getChildCount(); i++) {
                TreeNode childNode = node.getChildAt(i);
                TreePath path = parent.pathByAddingChild(childNode);
                expandAll(tree, path, expand);
            }
        }

        if (expand) {
            tree.expandPath(parent);
        } else {
            tree.collapsePath(parent);
        }
    }
}

Related

  1. expandAll(JTree t)
  2. expandAll(JTree tree)
  3. expandAll(JTree tree)
  4. expandAll(JTree tree)
  5. expandAll(JTree tree, boolean expand)
  6. expandAllNode(JTree tree, TreePath parent)
  7. expandAllNodes(final JTree tree)
  8. expandAllNodes(JTree tree)
  9. expandAllNodes(JTree tree)