Example usage for javax.swing JTree expandRow

List of usage examples for javax.swing JTree expandRow

Introduction

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

Prototype

int expandRow

To view the source code for javax.swing JTree expandRow.

Click Source Link

Document

The row to expand during DnD.

Usage

From source file:Main.java

public static void expandTree(JTree tree) {
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
    @SuppressWarnings("unchecked")
    Enumeration<DefaultMutableTreeNode> e = root.breadthFirstEnumeration();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
        if (node.isLeaf())
            continue;
        int row = tree.getRowForPath(new TreePath(node.getPath()));
        tree.expandRow(row);
    }/*from ww w . j  av a  2 s  . c o m*/
}

From source file:Main.java

public static JComponent makeUI() {
    JTree tree = new JTree();
    TreeModel model = tree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    Enumeration e = root.breadthFirstEnumeration();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
        Object o = node.getUserObject();
        if (o instanceof String) {
            node.setUserObject(new CheckBoxNode((String) o, false));
        }/*from  ww w .  j  a va2  s. c  o  m*/
    }
    tree.setEditable(true);
    tree.setCellRenderer(new CheckBoxNodeRenderer());
    tree.setCellEditor(new CheckBoxNodeEditor());
    tree.expandRow(0);
    return new JScrollPane(tree);
}

From source file:Main.java

public Main() {
    super();/* w  w  w .  ja  va 2s  . c o m*/
    JTree tree = new JTree();
    for (int i = 0; i < tree.getRowCount(); i++) {
        tree.expandRow(i);
    }

    final JScrollPane pane = new JScrollPane(tree) {
        Dimension prefSize = new Dimension(200, 150);

        public Dimension getPreferredSize() {
            return prefSize;
        }
    };

    pane.getVerticalScrollBar().addAdjustmentListener(e -> {
        JViewport vp = pane.getViewport();
        if (vp.getView().getHeight() <= vp.getHeight() + vp.getViewPosition().y) {
            System.out.println("End");
        }
    });

    add(pane);
}

From source file:com.edduarte.protbox.ui.windows.RestoreFileWindow.java

private void expandTree(JTree tree) {
    for (int i = 0; i < tree.getRowCount(); i++)
        tree.expandRow(i);
}

From source file:eu.europa.ec.markt.dss.applet.view.validationpolicy.EditView.java

/**
 * fully expand the tree//from  ww  w.j  a  v  a 2 s  .  c  o  m
 *
 * @param tree
 */
private void expandTree(JTree tree) {
    // expand all
    for (int i = 0; i < tree.getRowCount(); i++) {
        tree.expandRow(i);
    }
}

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

/**
 * expand all nodes of the currently selected category, only works for tree categories.
 *///from  w  w w .  j av a  2 s. c om
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:src.gui.ItSIMPLE.java

/**
 * This method updates any parallel tree (e.g., planning, analysis) when a new project is opened or created
 * @param doc/*from w  ww  .  j  av a2  s  .  c o m*/
 * @param xmlRoot
 * @param newProjectNode 
 */
public void updateNewProjectParallelTree(DefaultTreeModel treeModel, JTree tree, Document doc, Element xmlRoot,
        ItTreeNode newProjectNode) {

    // plan simulation problem tree
    ItTreeNode problemsPlanTreeRoot = (ItTreeNode) treeModel.getRoot();
    //opening
    //ItTreeNode planProjectNode = (ItTreeNode)newProjectNode.clone();
    //new project
    //ItTreeNode planProjectNode = new ItTreeNode(xmlRoot.getChildText("name"), xmlRoot, null, null);
    ItTreeNode planProjectNode = newProjectNode;
    planProjectNode.setIcon(new ImageIcon("resources/images/project.png"));
    treeModel.insertNodeInto(planProjectNode, problemsPlanTreeRoot, problemsPlanTreeRoot.getChildCount());
    //check if this is a UML project
    if (xmlRoot.getName().equals("project")) {
        List<?> domains = doc.getRootElement().getChild("diagrams").getChild("planningDomains")
                .getChildren("domain");
        for (Iterator<?> iter = domains.iterator(); iter.hasNext();) {
            Element domain = (Element) iter.next();
            ItTreeNode planDomainNode = new ItTreeNode(domain.getChildText("name"), domain, null, null);
            planDomainNode.setIcon(new ImageIcon("resources/images/domain.png"));
            treeModel.insertNodeInto(planDomainNode, planProjectNode, planProjectNode.getChildCount());
            List<?> problems = domain.getChild("planningProblems").getChildren("problem");
            for (Iterator<?> iterator = problems.iterator(); iterator.hasNext();) {
                Element problem = (Element) iterator.next();
                ItTreeNode planProblemNode = new ItTreeNode(problem.getChildText("name"), problem, null, null);
                planProblemNode.setIcon(new ImageIcon("resources/images/planningProblem.png"));
                treeModel.insertNodeInto(planProblemNode, planDomainNode, planDomainNode.getChildCount());
            }
        }

    }
    //check if this is a PDDL project
    else if (xmlRoot.getName().equals("pddlproject")) {

        List<?> problems = doc.getRootElement().getChild("problemInstances").getChildren("pddlproblem");
        for (Iterator<?> iter = problems.iterator(); iter.hasNext();) {
            Element problem = (Element) iter.next();
            ItTreeNode planpddlProblemNode = new ItTreeNode(problem.getChildText("name"), problem, null, null);
            planpddlProblemNode.setIcon(new ImageIcon("resources/images/domain.png"));
            treeModel.insertNodeInto(planpddlProblemNode, planProjectNode, planProjectNode.getChildCount());
        }
    }
    tree.expandRow(0);
}

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

/**
 * {@inheritDoc}//from  w  w w. j a  v  a2s  . com
 */
public void expandNode(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("expandRow", new IRunnable() { //$NON-NLS-1$
                public Object run() {
                    tree.expandRow(row);

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

}

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

/**
 * Expands all nodes in a tree./*from   www .  ja  va2  s.  c o  m*/
 * 
 * @param tree
 *            A tree
 */
public static void expandTree(JTree tree) {
    for (int i = 1; i < tree.getRowCount(); i++) {
        tree.expandRow(i);
    }
    tree.setSelectionRow(0);
}

From source file:pcgen.gui2.tabs.CompanionInfoTab.java

private void selectCompanion(CompanionFacade compFacade) {
    TreeTableModel treeTableModel = companionsTable.getTreeTableModel();
    treeTableModel.getRoot();//w  w w . ja va2s  .  c  om
    TreePath path = null;

    JTree tree = companionsTable.getTree();
    String companionType = compFacade.getCompanionType();
    for (int i = 0; i < tree.getRowCount(); i++) {
        TreePath pathForRow = tree.getPathForRow(i);
        Object lastPathComponent = pathForRow.getLastPathComponent();
        if (lastPathComponent.toString().startsWith(companionType)) {
            tree.expandRow(i);
        } else if (lastPathComponent instanceof pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) {
            CompanionFacade rowComp = (CompanionFacade) ((pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) lastPathComponent)
                    .getValueAt(0);

            if (rowComp != null && rowComp.getFileRef().get() == compFacade.getFileRef().get()
                    && rowComp.getNameRef().get() == compFacade.getNameRef().get()
                    && rowComp.getRaceRef().get() == compFacade.getRaceRef().get()) {
                path = pathForRow;
            }
        }
    }
    if (path != null) {
        companionsTable.getTree().setSelectionPath(path);
        companionsTable.getTree().scrollPathToVisible(path);
    }
}