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

The following examples show how to use javax.swing.JTree#getRowBounds() . 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: DebuggingViewComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Store first visible node and its offset. Called when the view is scrolled
 * by the user.
 */
private void storeScrollPosition() {
    JTree tree = getJTree();
    if (tree != null) {
        int scrollTop = mainScrollPane.getViewport().getViewPosition().y;
        int row = tree.getClosestRowForLocation(tree.getRowBounds(0).x + 1,
                scrollTop);
        if (row >= 0) {
            TreePath path = tree.getPathForRow(row);
            if (path != null) {
                int offset = tree.getRowBounds(row).y - scrollTop;
                visibleTreePosition = new VisibleTreePosition(
                        path, offset);
                return;
            }
        } else {
            return;
        }
    }
    visibleTreePosition = null;
}
 
Example 2
Source File: DebuggingViewComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Store visible offset of an important node. Called when the view is
 * scrolled by ViewRefresher
 *
 * @param path Path to a node that should stay visible at the same position.
 */
private void storeScrollPosition(TreePath path) {
    JTree tree = getJTree();
    if (tree != null && path != null) {
        int row = tree.getRowForPath(path);
        if (row >= 0) {
            int scrollTop = mainScrollPane.getViewport().getViewPosition().y;
            int offset = tree.getRowBounds(row).y - scrollTop;
            visibleTreePosition = new VisibleTreePosition(
                    path, offset);
            return;
        } else {
            return;
        }
    }
    visibleTreePosition = null;
}
 
Example 3
Source File: JTreeNodeJavaElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private Rectangle getCellBounds() {
    Callable<Rectangle> x = new Callable<Rectangle>() {
        @Override
        public Rectangle call() {
            JTree tree = (JTree) parent.getComponent();
            return tree.getRowBounds(viewRow);
        }
    };
    try {
        return EventQueueWait.exec(x);
    } catch (Exception e) {
        return new Rectangle();
    }
}
 
Example 4
Source File: DebuggingViewComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Restore stored scroll position.
 */
private void restoreScrollPosition(boolean delayScrollWithMarkingDirtyRegion) {
    if (visibleTreePosition != null) {
        JTree tree = getJTree();
        if (tree != null) {
            int row = tree.getRowForPath(visibleTreePosition.getPath());
            if (row != -1) {
                Rectangle bounds = tree.getRowBounds(row);
                if (bounds != null) {
                    int scrollY = bounds.y - visibleTreePosition.getOffset();
                    JViewport viewport = mainScrollPane.getViewport();
                    Rectangle rect = viewport.getViewRect();
                    rect.y = scrollY;
                    if (!rect.isEmpty()) {
                        JComponent view = (JComponent) viewport.getView();
                        if (delayScrollWithMarkingDirtyRegion) {
                            RepaintManager.currentManager(viewport).addDirtyRegion(
                                    view,
                                    rect.x, rect.x, rect.width, rect.height);
                        }
                        ignoreScrollAdjustment = true;
                        try {
                            view.scrollRectToVisible(
                                    rect);
                        } finally {
                            ignoreScrollAdjustment = false;
                        }
                    }
                }
            }
        }
    }
}
 
Example 5
Source File: JTreeNodeJavaElement.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private boolean isVisible(JTree tree, int row) {
    Rectangle visibleRect = tree.getVisibleRect();
    Rectangle cellRect = tree.getRowBounds(row);
    return SwingUtilities.isRectangleContainingRectangle(visibleRect, cellRect);
}