Example usage for java.awt Window getBounds

List of usage examples for java.awt Window getBounds

Introduction

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

Prototype

public Rectangle getBounds() 

Source Link

Document

Gets the bounds of this component in the form of a Rectangle object.

Usage

From source file:org.intermine.common.swing.WindowUtils.java

/**
 * Centre the window <code>win</code> over the window <code>parent</code>.
 * /*from w w  w  . j  a v a 2 s  . c o  m*/
 * @param win The Window to position.
 * @param parent The reference Window.
 */
public static void centreOverWindow(Window win, Window parent) {
    Rectangle parentBounds = parent.getBounds();
    Dimension windowSize = win.getSize();

    int x = (parentBounds.width - windowSize.width) / 2;
    int y = (parentBounds.height - windowSize.height) / 2;

    x = Math.max(0, x + parentBounds.x);
    y = Math.max(0, y + parentBounds.y);

    win.setLocation(x, y);
}