Example usage for java.awt Window setLocation

List of usage examples for java.awt Window setLocation

Introduction

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

Prototype

@Override
public void setLocation(int x, int y) 

Source Link

Document

The method changes the geometry-related data.

Usage

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 source file:Main.java

public static void center(Window window) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = window.getSize();
    frameSize.height = ((frameSize.height > screenSize.height) ? screenSize.height : frameSize.height);
    frameSize.width = ((frameSize.width > screenSize.width) ? screenSize.width : frameSize.width);
    window.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}

From source file:Main.java

public static final void centerOnScreen(Window window) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension windowSize = window.getSize();

    if (windowSize.height > screenSize.height)
        windowSize.height = screenSize.height;

    if (windowSize.width > screenSize.width)
        windowSize.width = screenSize.width;

    window.setLocation((screenSize.width - windowSize.width) / 2, (screenSize.height - windowSize.height) / 2);
}

From source file:Splash.java

/** Centre a Window, Frame, JFrame, Dialog, etc. */
public static void centre(Window w) {
    // After packing a Frame or Dialog, centre it on the screen.
    Dimension us = w.getSize(), them = Toolkit.getDefaultToolkit().getScreenSize();
    int newX = (them.width - us.width) / 2;
    int newY = (them.height - us.height) / 2;
    w.setLocation(newX, newY);
}

From source file:Main.java

public static void ShowWindowAtScreenCenter(Window window) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = window.getSize();
    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }//from ww w . ja  v  a2s  .co  m
    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }
    window.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    //      window.setVisible(true);
}

From source file:Main.java

public static void setToScreenCenter(Window window) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension windowSize = window.getSize();
    if (windowSize.height > screenSize.height) {
        windowSize.height = screenSize.height;
    }/*from   w w w  .  j a va 2  s .c o m*/
    if (windowSize.width > screenSize.width) {
        windowSize.width = screenSize.width;
    }
    window.setLocation((screenSize.width - windowSize.width) / 2, (screenSize.height - windowSize.height) / 2);
}

From source file:Main.java

/**
 * Centers the Frame on the screen/* w w  w .ja  v  a 2 s  .c  o  m*/
 */
public static void center(java.awt.Window frame) {
    // Get the size of the screen
    java.awt.Dimension dim = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

    // Determine the new location of the window
    int w = frame.getSize().width;
    int h = frame.getSize().height;
    int x = (dim.width - w) / 2;
    int y = (dim.height - h) / 2;

    // Move the window
    frame.setLocation(x, y);
}

From source file:Main.java

public static void centerFrame(Window frame) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = frame.getSize();
    screenSize.height = screenSize.height / 2;
    screenSize.width = screenSize.width / 2;
    size.height = size.height / 2;//from w  w  w  .j a  v a 2 s.  com
    size.width = size.width / 2;
    int y = screenSize.height - size.height;
    int x = screenSize.width - size.width;

    frame.setLocation(x, y);
}

From source file:Main.java

/**
 * Zentriert ein Window relativ zu dem Parent-Window
 * //from   ww  w .  ja  v  a2s . co  m
 * @param parent
 *            Parent-Window, wenn null, dann wird relativ zu dem Bildschirm
 *            zentriert
 * @param child
 *            Window das zentrirt werden soll.
 */
static public void centreWindow(Window parent, Window child) {
    if (child == null)
        return;
    Point parentLocation = null;
    Dimension parentSize = null;
    if (parent == null) {
        parentLocation = new Point(0, 0);
        parentSize = child.getToolkit().getScreenSize();
    } else {
        parentLocation = parent.getLocationOnScreen();
        parentSize = parent.getSize();
    }
    Dimension childSize = child.getSize();
    child.setLocation((int) (parentLocation.getX() + parentSize.getWidth() / 2 - childSize.getWidth() / 2),
            (int) (parentLocation.getY() + parentSize.getHeight() / 2 - childSize.getHeight() / 2));
}

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 {//from  ww  w.j  a  v  a 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);
}