Example usage for java.awt Window getLocation

List of usage examples for java.awt Window getLocation

Introduction

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

Prototype

public Point getLocation() 

Source Link

Document

Gets the location of this component in the form of a point specifying the component's top-left corner.

Usage

From source file:Main.java

public static void centerWindow(Window w, Window reference) {
    Point refCorner = reference.getLocation();
    Point center = new Point(refCorner.x + reference.getWidth() / 2, refCorner.y + reference.getHeight() / 2);
    centerWindow(w, center);//from  www. j a v  a 2 s  .  co m
}

From source file:Utils.java

/**
 * <p/>/*from ww w  .  jav a  2s.  c o  m*/
 * Returns the <code>Point</code> at which a window should be placed in
 * order to be staggered slightly from another &quot;origin&quot; window to
 * ensure that the title areas of both windows remain visible to the user.
 * </p>
 *
 * @param originWindow Window from which the staggered location will be calculated
 *
 * @return location staggered from the upper left location of the origin
 *         window
 */
public static Point getPointForStaggering(Window originWindow) {
    Point origin = originWindow.getLocation();
    Insets insets = originWindow.getInsets();
    origin.x += insets.top;
    origin.y += insets.top;
    return origin;
}

From source file:Main.java

public static GraphicsDevice getCurrentScreen(Window window) {
    return getCurrentScreen(window.getLocation(), window.getSize());
}

From source file:Main.java

/**
 * Centers the given window over its owner window.
 *
 * @param window//from   w  w w  .ja va 2 s .co m
 *            The window to center
 * @param ownerWindow
 *            The window to center the other window over
 */
public static void center(Window window, Window ownerWindow) {
    Point ownerWindowLocation = ownerWindow.getLocation();
    Dimension ownerWindowDimension = ownerWindow.getSize();
    Dimension windowSize = window.getSize();
    window.setLocation(ownerWindowLocation.x + (ownerWindowDimension.width - windowSize.width) / 2,
            ownerWindowLocation.y + (ownerWindowDimension.height - windowSize.height) / 2);
}

From source file:Main.java

public static GraphicsConfiguration getGraphicsConfigurationForCurrentLocation(Window window) {
    GraphicsConfiguration ownedConfig = window.getGraphicsConfiguration();
    Point currLocation = window.getLocation();
    // Shortcut for "owned" case
    if (ownedConfig.getBounds().contains(currLocation))
        return ownedConfig;

    // Search for the right screen
    GraphicsDevice[] screens = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    for (GraphicsDevice screen : screens)
        for (GraphicsConfiguration config : screen.getConfigurations())
            if (config.getBounds().contains(currLocation))
                return config;

    // If none found, lets return the "owned" one
    return ownedConfig;
}

From source file:Main.java

public static void centerOver(Window innerWindow, Window outterWindow) {

    Dimension innerSize = innerWindow.getSize();
    Dimension outterSize = outterWindow.getSize();

    int x = outterWindow.getLocation().x + (outterSize.width - innerSize.width) / 2;
    int y = outterWindow.getLocation().y + (outterSize.height - innerSize.height) / 2;

    innerWindow.setLocation(x, y);//from w ww .j  a  v a2s.  c  o  m
}

From source file:Main.java

public static void setWindowLocationRelativeTo(Window window, Window relativeWindow) {
    Rectangle windowBounds = window.getBounds();
    Dimension rwSize = relativeWindow.getSize();
    Point rwLoc = relativeWindow.getLocation();

    int dx = rwLoc.x + ((rwSize.width - windowBounds.width) >> 1);
    int dy = rwLoc.y + ((rwSize.height - windowBounds.height) >> 1);
    Dimension ss = window.getToolkit().getScreenSize();

    if (dy + windowBounds.height > ss.height) {
        dy = ss.height - windowBounds.height;
        dx = rwLoc.x < (ss.width >> 1) ? rwLoc.x + rwSize.width : rwLoc.x - windowBounds.width;
    }/*from  w  w  w. j  a  va  2s.  c o m*/
    if (dx + windowBounds.width > ss.width) {
        dx = ss.width - windowBounds.width;
    }
    if (dx < 0) {
        dx = 0;
    }
    if (dy < 0) {
        dy = 0;
    }
    window.setLocation(dx, dy);
}

From source file:Main.java

public static void centerOnScreen(Window w, Window parent) {
    Rectangle r = new Rectangle();
    if (parent == null) {
        r.setSize(Toolkit.getDefaultToolkit().getScreenSize());
    } else {/*ww  w  .  j  a va  2s  . c  o m*/
        r.setLocation(parent.getLocation());
        r.setSize(parent.getSize());
    }
    // Determine the new location of the alert
    int x = r.x + (r.width - w.getWidth()) / 2;
    int y = r.y + (r.height - w.getHeight()) / 2;
    // Move the alert
    w.setLocation(x, y);
}

From source file:Main.java

/**
 * Centers the window on the screen./*  w  ww . j  a v a 2  s .co m*/
 * 
 * @param window The window to center.
 * @return The location or top-left corner.
 */
public static Point centerOnScreen(Window window) {
    Dimension screenSize = getScreenSize(window);
    Dimension windowSize = window.getSize();
    int x = (int) ((screenSize.getWidth() - windowSize.getWidth()) / 2);
    int y = (int) ((screenSize.getHeight() - windowSize.getHeight()) / 2);
    window.setLocation(x, y);
    return window.getLocation();
}

From source file:de.erdesignerng.util.ApplicationPreferences.java

public void updateWindowLocation(String aAlias, Window aWindow) {
    Point theLocation = aWindow.getLocation();
    windowDefinitions.put(WINDOWXPREFIX + aAlias, "" + theLocation.x);
    windowDefinitions.put(WINDOWYPREFIX + aAlias, "" + theLocation.y);
}