Example usage for javax.swing JTree collapsePath

List of usage examples for javax.swing JTree collapsePath

Introduction

In this page you can find the example usage for javax.swing JTree collapsePath.

Prototype

public void collapsePath(TreePath path) 

Source Link

Document

Ensures that the node identified by the specified path is collapsed and viewable.

Usage

From source file:Main.java

private static void expandAll(JTree tree, TreePath parent, boolean expand) {
    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);
            expandAll(tree, path, expand);
        }/*from   ww w .  j  av a2  s .  c o  m*/
    }

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

From source file:Main.java

/** 
 * Expand (or collapse) the children nodes of specified node of a JTree for a certain depth.
 * @param tree Tree of which we want to expand the nodes.
 * @param parent Parent node./*  ww  w .  jav  a 2s .c o m*/
 * @param expand <code>true</code> to expand the nodes.  <code>false</code> to collapse the nodes. 
 * @param depth Depth of children to expand or collapse.
 */
public static void expandNodes(JTree tree, TreePath parent, boolean expand, int depth) {
    if (parent == null || depth == 0)
        return;

    Object node = parent.getLastPathComponent();
    if (node != null) {
        for (int i = 0; i < tree.getModel().getChildCount(node); i++) {
            Object child = tree.getModel().getChild(node, i);
            TreePath path = parent.pathByAddingChild(child);
            expandNodes(tree, path, expand, depth - 1);
        }
    }

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

From source file:TreeUtil.java

public static void expandAll(JTree tree, TreePath parent, boolean expand) {
    // Traverse children
    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);
            expandAll(tree, path, expand);
        }// w w w  .ja  v a  2  s  . c  om
    }
    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}

From source file:Main.java

static private void expandAll(JTree tree, TreePath parent, boolean expand) {
    // Traverse children
    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);
            expandAll(tree, path, expand);
        }/*from  w  w  w  . j a  va 2s . c o m*/
    }
    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}

From source file:TreeUtils.java

public static void expandAll(JTree tree, TreePath parent, boolean expand) {
    // Traverse children
    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);
            expandAll(tree, path, expand);
        }//from  w ww .  j  a va 2s . co m
    }

    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}

From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java

private static void expandAll(JTree tree, TreePath treePath, boolean expand, int maxLevel, int currentLevel) {
    if (maxLevel != -1 && currentLevel >= maxLevel - 1) {
        return;/*from  w  ww  . java2s.  c o m*/
    }

    TreeNode node = (TreeNode) treePath.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements();) {
            TreeNode n = e.nextElement();

            TreePath path = treePath.pathByAddingChild(n);
            expandAll(tree, path, expand, maxLevel, currentLevel + 1);
        }
    }

    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(treePath);
    } else {
        tree.collapsePath(treePath);
    }
}

From source file:gdt.jgui.entity.JEntityStructurePanel.java

private void expandAll(JTree tree, TreePath path, boolean expand) {
    TreeNode node = (TreeNode) path.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        Enumeration enumeration = node.children();
        while (enumeration.hasMoreElements()) {
            TreeNode n = (TreeNode) enumeration.nextElement();
            TreePath p = path.pathByAddingChild(n);
            expandAll(tree, p, expand);/*from   www .ja va  2s . c  o  m*/
        }
    }
    if (expand) {
        tree.expandPath(path);
    } else {
        tree.collapsePath(path);
    }
}

From source file:gdt.jgui.entity.JEntityDigestDisplay.java

private void expandAll(JTree tree, TreePath path, boolean expand) {
    TreeNode node = (TreeNode) path.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        Enumeration enumeration = node.children();
        while (enumeration.hasMoreElements()) {
            DefaultMutableTreeNode n = (DefaultMutableTreeNode) enumeration.nextElement();
            TreePath p = path.pathByAddingChild(n);
            expandAll(tree, p, expand);//w ww . j  av  a  2  s .c  om
        }
    }
    if (expand) {
        tree.expandPath(path);
    } else {
        tree.collapsePath(path);
    }
}

From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java

/**
 * Expands or collapses the specified tree according to the
 * <code>expand</code>-parameter.
 *//*  w w  w. j  a v  a  2s .  c om*/
private void expandTree(JTree currentTree, TreePath parent, boolean expand) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements();) {
            TreePath path = parent.pathByAddingChild(e.nextElement());
            expandTree(currentTree, path, expand);
        }
    }
    if (expand) {
        currentTree.expandPath(parent);
    } else {
        currentTree.collapsePath(parent);
    }
}

From source file:gdt.jgui.entity.index.JIndexPanel.java

private void expandAll(JTree tree, TreePath parent, boolean expand) {

    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);
            expandAll(tree, path, expand);
        }//from ww  w.j av a  2  s  .c o  m
    }
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}