Example usage for java.awt Container getBounds

List of usage examples for java.awt Container getBounds

Introduction

In this page you can find the example usage for java.awt Container getBounds.

Prototype

public Rectangle getBounds(Rectangle rv) 

Source Link

Document

Stores the bounds of this component into "return value" rv and return rv.

Usage

From source file:Main.java

/**
 * Finds the real bounds of the component relative to the root Window
 *
 * @param container The container to find the bounds for.
 * @param rect A Rectangle to store the bounds in. This same object is
 *             returned./*from   w w w  .  j  a v  a  2  s .  c o  m*/
 * @return The real bounds of the container.
 */
public static Rectangle getRealBounds(Container container, Rectangle rect) {
    container.getBounds(rect);
    for (Container c = container.getParent(); !(c instanceof Window); c = c.getParent()) {
        Point p = c.getLocation();
        rect.x += p.x;
        rect.y += p.y;
    }
    return rect;
}