Example usage for javax.swing JTree collapseRow

List of usage examples for javax.swing JTree collapseRow

Introduction

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

Prototype

public void collapseRow(int row) 

Source Link

Document

Ensures that the node in the specified row is collapsed.

Usage

From source file:Main.java

public static void collapseAllNodes(JTree tree) {
    int row = tree.getRowCount() - 1;

    while (row > 0) {
        tree.collapseRow(row);
        --row;//from w  w  w  . j a  v a  2s. c  o m
    }
}

From source file:Main.java

public static void fullSelectionCollapse(JTree tree) {
    int startRow = tree.getLeadSelectionRow();
    int stopRow = getStopRow(tree, startRow);
    for (int i = stopRow - 1; i >= startRow; --i) {
        tree.collapseRow(i);
    }/*from  ww  w .  ja v  a 2 s . c  o m*/
}

From source file:com.pironet.tda.TDA.java

/**
 * expand all nodes of the currently selected category, only works for tree categories.
 *///from  w  ww.  j av  a  2s . com
private void expandAllCatNodes(boolean expand) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    JTree catTree = (JTree) ((TreeCategory) node.getUserObject()).getCatComponent(this);
    if (expand) {
        for (int i = 0; i < catTree.getRowCount(); i++) {
            catTree.expandRow(i);
        }
    } else {
        for (int i = 0; i < catTree.getRowCount(); i++) {
            catTree.collapseRow(i);
        }
    }
}

From source file:org.eclipse.jubula.rc.swing.tester.util.TreeOperationContext.java

/**
 * {@inheritDoc}//  w  w  w. java  2s  . c  o  m
 */
public void collapseNode(Object node) {
    final JTree tree = (JTree) getTree();
    final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(tree.getClass().getClassLoader());
        final int row = getRowForTreeNode(node);
        final Rectangle nodeBounds = getNodeBounds(node);
        final boolean collapsed = tree.isCollapsed(row);
        boolean doAction = isExpanded(node);
        final IEventThreadQueuer queuer = new EventThreadQueuerAwtImpl();

        queuer.invokeAndWait("scrollRowToVisible", new IRunnable() { //$NON-NLS-1$
            public Object run() {
                tree.scrollRowToVisible(row);

                return null;
            }
        });

        Rectangle visibleNodeBounds = getVisibleRowBounds(nodeBounds);
        getRobot().move(tree, visibleNodeBounds);
        if (doAction) {
            if (log.isDebugEnabled()) {
                log.debug((collapsed ? "Expanding" : "Collapsing") + " node: " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                        + node);
                log.debug("Row           : " + row); //$NON-NLS-1$
                log.debug("Node bounds   : " + visibleNodeBounds); //$NON-NLS-1$
            }
            queuer.invokeAndWait("collapseRow", new IRunnable() { //$NON-NLS-1$
                public Object run() {
                    tree.collapseRow(row);

                    return null;
                }
            });
        }
    } finally {
        Thread.currentThread().setContextClassLoader(oldCl);
    }

}

From source file:org.notebook.gui.widget.GuiUtils.java

/**
 * Collapses all nodes in a tree.//from w  ww.jav a2s .c o  m
 * 
 * @param tree
 *            the tree
 */
public static void collapseTree(JTree tree) {
    for (int i = tree.getRowCount() - 1; i > 0; i--) {
        tree.collapseRow(i);
    }
    tree.setSelectionRow(0);
}