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

/**
 * Centers a {@link Window} at the center of the screen.<br/>
 * Windows like {@link JDialog} and {@link JFrame} (and others) that extend from {@link Window} applies for this method.
 * /* ww w.jav  a2 s. c  o m*/
 * @param window 
 */
public static void centerWindow(Window window) {
    window.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width) / 2 - window.getWidth() / 2,
            (Toolkit.getDefaultToolkit().getScreenSize().height) / 2 - window.getHeight() / 2);
}

From source file:Main.java

/**
 *
 * @deprecated  Use automatic RitDialog centering facilities
 *///from   w  w  w. j  a v  a2  s .c  o m
public static void centerWindowOnScreen(Window window) {
    Dimension dim = window.getToolkit().getScreenSize();
    window.setLocation((dim.width - window.getWidth()) / 2, (dim.height - (window.getHeight())) / 2);
}

From source file:Main.java

public static void setLocationRelativeTo(Window child, Window parent) {
    Dimension d = parent.getSize();
    Dimension u = child.getSize();
    child.setLocation((int) ((d.getWidth() / 2) - (u.getWidth() / 2)),
            (int) ((d.getHeight() / 2) - (u.getHeight() / 2)));
}

From source file:Main.java

public static void center(Window window) {
    Dimension screen = window.getToolkit().getScreenSize();
    window.setLocation((screen.width - window.getWidth()) / 2, (screen.height - window.getHeight()) / 2);
}

From source file:Main.java

/** GUI utility (set frame on the center of screen) */
public static void setCenter(Window w) {
    Dimension scSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension wndSize = w.getSize();
    w.setLocation((scSize.width - wndSize.width) / 2, (scSize.height - wndSize.height) / 2);
}

From source file:Main.java

private static void centerWindow(Window w, Point center) {
    int x = center.x - w.getWidth() / 2;
    int y = center.y - w.getHeight() / 2;
    w.setLocation(x, y);
}

From source file:Main.java

/**
 * {@link Window#pack() Packs} the given window and positions it so that its
 * center stays the same.//from ww  w  . ja  v a  2  s.co m
 *
 * @param window
 *            The window to pack and recenter
 */
public static void repackCentered(Window window) {
    Point center = getCenter(window.getBounds());
    window.pack();
    window.setLocation((center.x - window.getWidth() / 2), (center.y - window.getHeight() / 2));
    window.repaint();
}

From source file:Main.java

public static void centerOnScreen(Window window) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = window.getSize();
    window.setLocation((screenSize.width - size.width) / 2, (screenSize.height - size.height) / 2);
}

From source file:Main.java

/**
 * Move the specified window to the center of the screen. Cautious, it may
 * occupy two different screens if the system has two or more combined
 * screens.//from ww  w.  j a  v a2s.  c o m
 * 
 * @param window
 *            the specified window
 */
public static void setWindowToScreenCenter(Window window) {
    int screenWidth = window.getToolkit().getScreenSize().width;
    int screenHeight = window.getToolkit().getScreenSize().height;
    window.setLocation(screenWidth / 2 - window.getSize().width / 2,
            screenHeight / 2 - window.getSize().height / 2);
}

From source file:Main.java

public static void centerWindowOnScreen(Window window) {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    window.setLocation((int) (screenSize.getWidth() / 2 - window.getWidth() / 2),
            (int) (screenSize.getHeight() / 2 - window.getHeight() / 2));
}