Example usage for javax.swing JTree getRowCount

List of usage examples for javax.swing JTree getRowCount

Introduction

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

Prototype

@BeanProperty(bound = false)
public int getRowCount() 

Source Link

Document

Returns the number of viewable nodes.

Usage

From source file:it.unibas.spicygui.Utility.java

public static void expandAll(JTree tree) {
    int row = 0;/*  ww  w . jav a 2s.co m*/
    while (row < tree.getRowCount()) {
        tree.expandRow(row);
        row++;
    }
}

From source file:Main.java

public Main() {
    super();/*w  w w.  ja  v  a  2  s  .  c  om*/
    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// ww  w  . j a  v  a2  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:it.unibas.spicygui.controllo.datasource.operators.CreaWidgetAlberi.java

private void scansioneAlbero(JTree albero, Component source, Component target, boolean sourceFlag) {
    //VEcchio codice che mette widget solo per le foglie
    //        for (int i = 0; i < listaFoglie.size(); i++) {
    //            int tmp = (Integer) listaFoglie.get(i);
    for (int i = 0; i < albero.getRowCount(); i++) {
        TreePath treePath = albero.getPathForRow(i);
        if (treePath != null && albero.isVisible(treePath)) {
            if (logger.isTraceEnabled()) {
                logger.trace("punto trovato: " + albero.getPathBounds(treePath).getLocation());
            }//from ww w.j  a  va  2s . c om
            Point convertedPoint = SwingUtilities.convertPoint(source,
                    albero.getPathBounds(treePath).getLocation(), target);
            createWidget(convertedPoint, albero, treePath, sourceFlag);
            if (logger.isTraceEnabled()) {
                logger.trace("punto convertito: " + convertedPoint);
            }
        }
    }
    contatore = -1;
    listaFoglie = new ArrayList();
}

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

/**
 * expand all nodes of the currently selected category, only works for tree categories.
 *//*from  w  ww .ja va 2  s.co  m*/
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.executequery.gui.browser.TreeFindAction.java

protected boolean changed(JComponent comp, String searchString, Position.Bias bias) {

    if (StringUtils.isBlank(searchString)) {

        return false;
    }/*www.java 2 s.co m*/

    JTree tree = (JTree) comp;
    String prefix = searchString;

    if (ignoreCase()) {

        prefix = prefix.toUpperCase();
    }

    boolean wildcardStart = prefix.startsWith("*");
    if (wildcardStart) {

        prefix = prefix.substring(1);

    } else {

        prefix = "^" + prefix;
    }
    prefix = prefix.replaceAll("\\*", ".*");

    Matcher matcher = Pattern.compile(prefix).matcher("");
    List<TreePath> matchedPaths = new ArrayList<TreePath>();
    for (int i = 1; i < tree.getRowCount(); i++) {

        TreePath path = tree.getPathForRow(i);
        String text = tree.convertValueToText(path.getLastPathComponent(), tree.isRowSelected(i),
                tree.isExpanded(i), true, i, false);

        if (ignoreCase()) {

            text = text.toUpperCase();
        }

        //            if ((wildcardStart && text.contains(prefix)) || text.startsWith(prefix, 0)) {
        //
        //                matchedPaths.add(path);
        //            }

        matcher.reset(text);
        if (matcher.find()) {

            matchedPaths.add(path);
        }

    }

    foundValues(matchedPaths);

    return !(matchedPaths.isEmpty());
}

From source file:org.executequery.gui.browser.TreeFindAction.java

public TreePath getNextMatch(JTree tree, String prefix, int startingRow, Position.Bias bias) {

    int max = tree.getRowCount();
    if (prefix == null) {
        throw new IllegalArgumentException();
    }/*from   w w  w.  j av a  2 s . c  o m*/
    if (startingRow < 0 || startingRow >= max) {
        throw new IllegalArgumentException();
    }

    if (ignoreCase()) {
        prefix = prefix.toUpperCase();
    }

    // start search from the next/previous element froom the
    // selected element
    int increment = (bias == null || bias == Position.Bias.Forward) ? 1 : -1;

    int row = startingRow;
    do {

        TreePath path = tree.getPathForRow(row);
        String text = tree.convertValueToText(path.getLastPathComponent(), tree.isRowSelected(row),
                tree.isExpanded(row), true, row, false);

        if (ignoreCase()) {

            text = text.toUpperCase();
        }

        if (text.startsWith(prefix)) {

            return path;
        }

        row = (row + increment + max) % max;

    } while (row != startingRow);

    return null;
}

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

/**
 * Collapses all nodes in a tree.//w  w  w. j a va  2s  .c om
 * 
 * @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);
}

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

/**
 * Expands all nodes in a tree.//from  w  w w  . j  av a  2  s.co 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);
}