Example usage for javax.swing JTree getVisibleRect

List of usage examples for javax.swing JTree getVisibleRect

Introduction

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

Prototype

@BeanProperty(bound = false)
public Rectangle getVisibleRect() 

Source Link

Document

Returns the Component's "visible rectangle" - the intersection of this component's visible rectangle, new Rectangle(0, 0, getWidth(), getHeight()), and all of its ancestors' visible rectangles.

Usage

From source file:JTreeUtil.java

private static void autoscroll(JTree tree, Point cursorLocation) {
    Insets insets = DEFAULT_INSETS;
    Rectangle outer = tree.getVisibleRect();
    Rectangle inner = new Rectangle(outer.x + insets.left, outer.y + insets.top,
            outer.width - (insets.left + insets.right), outer.height - (insets.top + insets.bottom));
    if (!inner.contains(cursorLocation)) {
        Rectangle scrollRect = new Rectangle(cursorLocation.x - insets.left, cursorLocation.y - insets.top,
                insets.left + insets.right, insets.top + insets.bottom);
        tree.scrollRectToVisible(scrollRect);
    }/*ww w. ja v a 2s . co m*/
}