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

The following examples show how to use javax.swing.JTree#scrollPathToVisible() . 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: MainView.java    From HiJson with Apache License 2.0 6 votes vote down vote up
private void findTreeChildValue(String findText,List<TreePath> treePathLst) {
        JTree tree = getTree();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode)tree.getModel().getRoot();
        Enumeration e = root.depthFirstEnumeration();
        treePathLst.clear();
        curPos = 0;
        while (e.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
            if (node.isLeaf()) {
                String str = node.toString();
                if (str.substring(2).indexOf(findText) >= 0) {
                    tree.expandPath(new TreePath(node.getPath()));
                    TreePath tp = expandTreeNode(tree,node.getPath(), true);
                    treePathLst.add(tp);
                }
            }
        }
        if(!treePathLst.isEmpty()){
            tree.setSelectionPath(treePathLst.get(0));
            tree.scrollPathToVisible(treePathLst.get(0));
        }
//        return treePathLst;
    }
 
Example 2
Source File: LibraryTreePanel.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the tree.
 * 
 * @param root the root node
 */
protected void createTree(LibraryTreeNode root) {
  treeModel = new DefaultTreeModel(root);
  tree = new JTree(treeModel) {
  	public JToolTip createToolTip() {
  		return new JMultiLineToolTip();
  	}
  };
  if (root.createChildNodes()) {
   LibraryTreeNode lastNode = (LibraryTreeNode)root.getLastChild();
 	TreePath path = new TreePath(lastNode.getPath());
 	tree.scrollPathToVisible(path);
  }
  treeNodeRenderer = new LibraryTreeNodeRenderer();
  tree.setCellRenderer(treeNodeRenderer);
  tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  ToolTipManager.sharedInstance().registerComponent(tree);
  // listen for tree selections and display the contents
  tree.addTreeSelectionListener(treeSelectionListener);
  // listen for mouse events to display node info and inform propertyChangeListeners
  tree.addMouseListener(treeMouseListener);
  // put tree in scroller
  treeScroller.setViewportView(tree);
}
 
Example 3
Source File: TreeSearch.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public static TreeSearch installForOR(JTree tree) {
    return new TreeSearch(tree) {
        @Override
        public void selectAndSrollTo(TreeNode node) {
            if (node instanceof ORObjectInf) {
                TreePath path = ((ORObjectInf) node).getTreePath();
                tree.setSelectionPath(path);
                tree.scrollPathToVisible(path);
            } else {
                super.selectAndSrollTo(node);
            }
        }
    };
}
 
Example 4
Source File: RepositoryTreeUtil.java    From rapidminer-studio with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Sets selected paths to the previous path(s) saved by {@link #saveSelectionPath(TreePath)} or
 * ##{@link #saveSelectionPaths(TreePath[])}. Scrolls to the first selected path.
 *
 * @param tree
 *            The related tree, containing the path(s)
 */
public void restoreSelectionPaths(JTree tree) {
	if (selectedPaths != null) {
		tree.setSelectionPaths(selectedPaths);
		tree.scrollPathToVisible(tree.getSelectionPath());
	}
}