Example usage for java.awt Window getHeight

List of usage examples for java.awt Window getHeight

Introduction

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

Prototype

public int getHeight() 

Source Link

Document

Returns the current height of this component.

Usage

From source file:Main.java

/**
 * Centers the {@link java.awt.Window} on the display
 *
 * @param window// w  ww.  j a  va  2  s . c  o  m
 *         Window to center
 */
public static void centerWindow(Window window) {
    Rectangle boundsOfAvailableSpace = getBoundsOfAvailableDisplaySpace(window);
    int offsetX = (boundsOfAvailableSpace.width - window.getWidth()) / 2;
    int offsetY = (boundsOfAvailableSpace.height - window.getHeight()) / 2;
    window.setLocation(offsetX, offsetY);
}

From source file:Main.java

public static void centerWindowOnScreen(Window window) {
    int screenHeight = (int) window.getToolkit().getScreenSize().getHeight();
    int screenWidth = (int) window.getToolkit().getScreenSize().getWidth();
    int x = (screenWidth - window.getWidth()) / 2;
    int y = (screenHeight - window.getHeight()) / 2;
    window.setLocation(x, y);//w w w. j  a  v a  2  s .c o  m
}

From source file:Main.java

/**
 * Center a window on screen.//from   www  .  j  a v a  2 s.  com
 *
 * @param w
 *          the window to center on screen.
 */
public static void centerInParent(Window w) {
    Container parent = w.getParent();
    if (parent != null) {
        Dimension parentSize = parent.getSize();
        w.setLocation(parent.getX() + (parentSize.width - w.getWidth()) / 2,
                parent.getY() + (parentSize.height - w.getHeight()) / 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));
}

From source file:Main.java

/**
 * Centers a Window on the screen<p>
 * Sets the window on the top left corner if the window's
 * dimensions are bigger than the screen's.
 *
 * @param window a Window object// w  ww  .  j a v a2s.  c  o m
 */
public static void centerOnScreen(Window window) {
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    double w = Math.min(window.getWidth(), screen.width);
    double h = Math.min(window.getHeight(), screen.height);
    int x = (int) (center.x - (w / 2));
    int y = (int) (center.y - (h / 2));

    Point corner = new Point((x >= 0 ? x : 0), (y >= 0 ? y : 0));

    window.setLocation(corner);
}

From source file:Main.java

public static void pack(Component c) {
    Window window = getFrame(c);
    window.pack();/*w  w  w  . j a  va  2 s  .  com*/
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension bounds = new Dimension();
    bounds.width = Math.min(window.getWidth(), screenSize.width * 8 / 10);
    bounds.height = Math.min(window.getHeight(), screenSize.height * 8 / 10);
    window.setSize(bounds);
}

From source file:Utils.java

public static Point getPointForCentering(Window window) {
    Rectangle usableBounds = getUsableDeviceBounds(window);
    int screenWidth = usableBounds.width;
    int screenHeight = usableBounds.height;
    int width = window.getWidth();
    int height = window.getHeight();

    return new Point(((screenWidth - width) / 2) + usableBounds.x,
            ((screenHeight - height) / 2) + usableBounds.y);
}

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(Window w, Window parent) {
    Rectangle r = new Rectangle();
    if (parent == null) {
        r.setSize(Toolkit.getDefaultToolkit().getScreenSize());
    } else {/*from  ww  w.j a  v a2 s. c om*/
        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

/**
 * Center the given window within the screen boundaries.
 *
 * @param window the window to be centered.
 *//* ww w.j av a  2s .com*/
public static void centerWindow(Window window) {
    Rectangle bounds;
    try {
        bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration().getBounds();
    } catch (Throwable t) {
        Toolkit tk = window.getToolkit();
        Dimension ss = tk.getScreenSize();
        bounds = new Rectangle(ss);
    }

    int width = window.getWidth(), height = window.getHeight();
    window.setBounds(bounds.x + (bounds.width - width) / 2, bounds.y + (bounds.height - height) / 2, width,
            height);
}