Example usage for java.awt Window getSize

List of usage examples for java.awt Window getSize

Introduction

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

Prototype

public Dimension getSize() 

Source Link

Document

Returns the size of this component in the form of a Dimension object.

Usage

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;
    }//www  .j  ava 2 s  .  c  o 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 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:Main.java

public static void centreDialogOnWindow(Window owner, JDialog dialog) {
    Point ownerPosition = owner.getLocationOnScreen();
    Dimension ownerSize = owner.getSize();
    Dimension dialogSize = dialog.getSize();
    int x = ownerPosition.x + (ownerSize.width / 2) - (dialogSize.width / 2);
    int y = ownerPosition.y + (ownerSize.height / 2) - (dialogSize.height / 2);
    dialog.setLocation(x, y);/*from  w w  w  . j a v a2s .  c  o m*/
}

From source file:Main.java

public static void centreDialogOnWindow(Window owner, FileDialog dialog) {
    Point ownerPosition = owner.getLocationOnScreen();
    Dimension ownerSize = owner.getSize();
    Dimension dialogSize = dialog.getSize();
    int x = ownerPosition.x + (ownerSize.width / 2) - (dialogSize.width / 2);
    int y = ownerPosition.y + (ownerSize.height / 2) - (dialogSize.height / 2);
    dialog.setLocation(x, y);//from  www.j  a v a2s. c o m
}

From source file:Main.java

public static void centerOnScreen(Window window) {

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension windowSize = window.getSize();

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

    window.setLocation(x, y);/*from w ww  .j a  va2  s .c o  m*/
}

From source file:Main.java

/**
 * Center the given <code>windows</code> in relative to the given <code>invoker</code>.
 * @param invoker Reference window for the window to center.
 * @param window The window instance to center.
 *///from   w  w  w .  j av a2  s .  c  o  m
public static void centerOnWindow(Window invoker, Window window) {
    Point invokerLocationOnScreen = invoker.getLocationOnScreen();
    Dimension invokerSize = invoker.getSize();
    Dimension windowSize = window.getSize();

    window.setLocation(invokerLocationOnScreen.x + (invokerSize.width / 2) - (windowSize.width / 2),
            invokerLocationOnScreen.y + ((invokerSize.height / 2) - (windowSize.height / 2) / 2));
}

From source file:Main.java

/**
 * centers the frame in the center of the screen
 *
 * @param pFrame Frame to center/*from   www. j  a v a 2  s .com*/
 */
static public void centerWindow(Window pFrame) {
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    center.x = center.x - (int) pFrame.getSize().getWidth() / 2;
    center.y = center.y - (int) pFrame.getSize().getHeight() / 2;
    pFrame.setLocation(center);
}

From source file:Main.java

public static void centerOnScreenAtLocation(Window window, Point desiredLocation) {
    GraphicsDevice currentScreen = getCurrentScreen(desiredLocation, window.getSize());
    Rectangle2D screenBounds = currentScreen.getDefaultConfiguration().getBounds();
    window.setLocation((int) screenBounds.getCenterX() - (window.getWidth() / 2),
            (int) screenBounds.getCenterY() - (window.getHeight() / 2));
}

From source file:Main.java

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

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

    window.setLocation(x, y);//w w w. j  ava2 s  .  c  o m
}

From source file:Main.java

/**
 * Centers the window on the screen.//from   w w  w.j  a  v  a 2s .c o  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();
}