List of usage examples for javax.swing JTree scrollRowToVisible
public void scrollRowToVisible(int row)
From source file:TreeNodeVector.java
public static void main(final String args[]) { JFrame frame = new JFrame("JTreeSample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vector<String> v1 = new TreeNodeVector<String>("Two", new String[] { "Mercury", "Venus", "Mars" }); Vector<Object> v2 = new TreeNodeVector<Object>("Three"); v2.add(System.getProperties()); v2.add(v1);//from ww w. ja va 2s .c o m Object rootNodes[] = { v1, v2 }; Vector<Object> rootVector = new TreeNodeVector<Object>("Root", rootNodes); JTree tree = new JTree(rootVector); frame.add(new JScrollPane(tree), BorderLayout.CENTER); tree.expandRow(1); tree.scrollRowToVisible(2); tree.revalidate(); frame.setSize(300, 300); frame.setVisible(true); }
From source file:org.eclipse.jubula.rc.swing.tester.util.TreeOperationContext.java
/** * {@inheritDoc}/*from w ww.j av a2 s.c o m*/ */ public void collapseNode(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("collapseRow", new IRunnable() { //$NON-NLS-1$ public Object run() { tree.collapseRow(row); return null; } }); } } finally { Thread.currentThread().setContextClassLoader(oldCl); } }
From source file:org.eclipse.jubula.rc.swing.tester.util.TreeOperationContext.java
/** * {@inheritDoc}/*from w ww. j a v a 2s. c om*/ */ 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); } }