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 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

/**
 * Centraliza a janela na tela/*from  w  w w  . j  a v a  2 s.c  o  m*/
 * @param w janela a ser centralizada
 */
public static void center(Window w) {
    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 center(Window window) {
    final Dimension size = window.getSize();
    final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    final int locX = (screen.width - size.width) / 2;
    final int locY = (screen.height - size.height) / 2;
    window.setLocation(locX, locY);/*from www  .ja  v  a2s.  c  om*/
}

From source file:Main.java

public static Point getScreenCenterLocation(Window w) {
    Dimension size = w.getSize();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    double desktopHeight = toolkit.getScreenSize().getHeight();
    double desktopWidth = toolkit.getScreenSize().getWidth();

    // To the left (hack for Ngoc's dual display)
    if (desktopWidth > 1600) {
        desktopWidth += 1600;/*from w w w  .j av  a2 s. co m*/
    }
    Point location = new Point();
    location.x = (int) (desktopWidth - size.getWidth()) / 2;
    location.y = (int) (desktopHeight - size.getHeight()) / 2;
    return location;
}

From source file:Main.java

/**
 * Centers a component according to the window location.
 * @param wnd The parent window/*  w  ww  . j a va 2  s  .  c o  m*/
 * @param cmp A component, usually a dialog
 */
public static void centerInWindow(Window wnd, Component cmp) {
    Dimension size = wnd.getSize();
    Point loc = wnd.getLocationOnScreen();
    Dimension cmpSize = cmp.getSize();
    loc.x += (size.width - cmpSize.width) / 2;
    loc.y += (size.height - cmpSize.height) / 2;
    cmp.setBounds(loc.x, loc.y, cmpSize.width, cmpSize.height);
}

From source file:Main.java

/** Gets the dimension of this window were it to be repacked. */
public static Dimension getRepackSize(final Window w) {
    final Dimension size = w.getSize();
    final Dimension pref = w.getPreferredSize();
    if (size.width >= pref.width && size.height >= pref.height)
        return size;
    return new Dimension(size.width < pref.width ? pref.width : size.width,
            size.height < pref.height ? pref.height : size.height);
}

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 ww w  .j a v  a 2  s  .  co m*/
}

From source file:Main.java

public static Point getPointForCentering(Dialog dialog, Window parent) {
    Dimension size = dialog.getSize();
    Dimension parentSize = parent.getSize();
    int centerX = (int) ((parentSize.getWidth() - size.getWidth()) / 2 + parent.getX());
    int centerY = (int) ((parentSize.getHeight() - size.getHeight()) / 2 + parent.getY());
    return new Point(centerX, centerY);
}

From source file:Main.java

/** Centers the given window within the specified bounds. */
public static void centerWindow(final Rectangle bounds, final Window window) {
    final Dimension w = window.getSize();
    int x = bounds.x + (bounds.width - w.width) / 2;
    int y = bounds.y + (bounds.height - w.height) / 2;
    if (x < 0)
        x = 0;/*from w ww  .j  a va2  s.com*/
    if (y < 0)
        y = 0;
    window.setLocation(x, y);
}

From source file:Main.java

/**
 * @param owner//w  ww . java 2  s.  c o  m
 * @param newConfigDialog
 */
public static void centerRelative(java.awt.Window main, java.awt.Window child) {
    java.awt.Dimension dim = main.getSize();
    Point _loc = center(dim, child);
    // Move the window
    _loc.translate(main.getX(), main.getY());
    child.setLocation(_loc);
}