List of usage examples for javax.swing JComponent getVisibleRect
@BeanProperty(bound = false)
public Rectangle getVisibleRect()
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. From source file:Main.java
public static void centerVertically(JComponent c, int from, int to, boolean withInsets) { Rectangle bounds = c.getBounds(); Insets i = withInsets ? EMPTY_INSETS : c.getInsets(); bounds.x = i.left;/*from w w w . ja v a 2s. c om*/ bounds.y = i.top; bounds.width -= i.left + i.right; bounds.height -= i.top + i.bottom; Rectangle visible = c.getVisibleRect(); visible.y = from - (visible.height + from - to) / 2; if (visible.y < bounds.y) visible.y = bounds.y; if (visible.y + visible.height > bounds.y + bounds.height) visible.y = bounds.y + bounds.height - visible.height; c.scrollRectToVisible(visible); }