Java Code Examples for javax.swing.JTree#isRootVisible()

The following examples show how to use javax.swing.JTree#isRootVisible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RTree.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private String getTextForNode(JTree tree, int row) {
    TreePath treePath = tree.getPathForRow(row);
    if (treePath == null) {
        return row + "";
    }
    StringBuilder sb = new StringBuilder();
    int start = tree.isRootVisible() ? 0 : 1;
    Object[] objs = treePath.getPath();
    for (int i = start; i < objs.length; i++) {
        String pathString;
        if (objs[i].toString() == null) {
            pathString = "";
        } else {
            pathString = escapeSpecialCharacters(getTextForNodeObject(tree, objs[i]));
        }
        sb.append("/" + pathString);
    }
    return sb.toString();
}
 
Example 2
Source File: JTreeJavaElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private TreePath getPath(JTree tree, String path) {
    String[] tokens = path.substring(1).split("(?<!\\\\)/");
    TreeModel treeModel = tree.getModel();
    if (treeModel == null) {
        throw new RuntimeException("Could not find model for tree");
    }
    Object rootNode = treeModel.getRoot();
    int start = tree.isRootVisible() ? 1 : 0;
    TreePath treePath = new TreePath(rootNode);
    StringBuilder searchedPath = new StringBuilder();
    if (tree.isRootVisible()) {
        String rootNodeText = unescapeSpecialCharacters(tokens[0]);
        searchedPath.append("/" + rootNodeText);
        assertTrue("JTree does not have a root node!", rootNode != null);
        assertTrue("JTree root node does not match: Expected </" + getPathText(tree, treePath) + "> Actual: <"
                + searchedPath.toString() + ">", searchedPath.toString().equals("/" + getPathText(tree, treePath)));
    }
    for (int i = start; i < tokens.length; i++) {
        String childText = unescapeSpecialCharacters(tokens[i]);
        searchedPath.append("/" + childText);
        boolean matched = false;
        tree.expandPath(treePath);
        for (int j = 0; j < treeModel.getChildCount(treePath.getLastPathComponent()); j++) {
            Object child = treeModel.getChild(treePath.getLastPathComponent(), j);
            TreePath childPath = treePath.pathByAddingChild(child);
            if (childText.equals(getPathText(tree, childPath))) {
                treePath = childPath;
                matched = true;
                break;
            }
        }
        if (!matched) {
            return null;
        }
    }
    return treePath;
}
 
Example 3
Source File: TreeUtil.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
/**
 * Collapse all nodes of a tree.
 *
 * @param tree The tree whose nodes to expand.
 */
public static void collapseAll(JTree tree) {
    TreePath pathToRoot = new TreePath(tree.getModel().getRoot());
    collapseAll(tree, pathToRoot);
    if (!tree.isRootVisible()) {
        tree.expandPath(pathToRoot);
    }
}
 
Example 4
Source File: TreeUtil.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public static void collapseAllFromNode(JTree tree, DBBrowserNode node) {
    TreePath pathToNode = new TreePath(node);
    collapseAll(tree, pathToNode);
    if (!tree.isRootVisible()) {
        tree.expandPath(pathToNode);
    }
}