Example usage for javax.swing JTree getRowForPath

List of usage examples for javax.swing JTree getRowForPath

Introduction

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

Prototype

public int getRowForPath(TreePath path) 

Source Link

Document

Returns the row that displays the node identified by the specified path.

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);//  w  w w  .jav a  2s  . c o m
    }
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserComponent.java

/**
 * Implemented as specified by the {@link Browser} interface.
 * @see Browser#setFoundInBrowser(Set)//from  w w w . j av  a 2  s.c  om
 */
public void setFoundInBrowser(Set nodes) {
    if (nodes == null || nodes.size() == 0) {
        model.setFoundNodes(null); // reset default value.
        model.setFoundNodeIndex(-1); // reset default value.
        view.getTreeDisplay().repaint();
        return;
    }
    List<Object> list = new ArrayList<Object>(nodes.size());
    Iterator i = nodes.iterator();

    final JTree tree = view.getTreeDisplay();
    while (i.hasNext())
        list.add(i.next());
    Comparator c = new Comparator() {
        public int compare(Object o1, Object o2) {
            TreeImageDisplay node1 = (TreeImageDisplay) o1;
            TreeImageDisplay node2 = (TreeImageDisplay) o2;
            int i1 = tree.getRowForPath(new TreePath(node1.getPath()));
            int i2 = tree.getRowForPath(new TreePath(node2.getPath()));
            return (i1 - i2);
        }
    };
    Collections.sort(list, c);
    model.setFoundNodes(list);
    model.setFoundNodeIndex(0);
    handleNodeDisplay((TreeImageDisplay) list.get(0));
    tree.repaint();
}