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:net.team2xh.crt.gui.util.GUIToolkit.java

/**
 * Centers a frame on screen/*from   w w  w .  j  a  v a 2s. c o  m*/
 *
 * @param frame Frame to center
 */
public static void centerFrame(java.awt.Window frame) {
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((screen.width - frame.getWidth()) / 2, (screen.height - frame.getHeight()) / 2);
}

From source file:op.tools.SYSTools.java

public static void center(java.awt.Window w) {
    Dimension us = w.getSize();//from  w  w w .ja  v  a  2  s. c  o  m
    Dimension them = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    int newX = (them.width - us.width) / 2;
    int newY = (them.height - us.height) / 2;
    w.setLocation(newX, newY);
}

From source file:org.intermine.common.swing.WindowUtils.java

/**
 * Centre the given window on the screen.
 * //  w  ww  .  ja  v a  2 s  . co  m
 * @param win The Window to position.
 */
public static void centreOnScreen(Window win) {
    Dimension screenRes = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension windowSize = win.getSize();

    int x = Math.max(0, (screenRes.width - windowSize.width) / 2);
    int y = Math.max(0, (screenRes.height - windowSize.height) / 2);

    win.setLocation(x, y);
}

From source file:org.intermine.common.swing.WindowUtils.java

/**
 * Centre the window <code>win</code> over the window <code>parent</code>.
 * //from w  w w.java 2  s.c o  m
 * @param win The Window to position.
 * @param parent The reference Window.
 */
public static void centreOverWindow(Window win, Window parent) {
    Rectangle parentBounds = parent.getBounds();
    Dimension windowSize = win.getSize();

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

    x = Math.max(0, x + parentBounds.x);
    y = Math.max(0, y + parentBounds.y);

    win.setLocation(x, y);
}

From source file:org.isatools.isacreatorconfigurator.configui.FieldInterface.java

private void showPopupInCenter(Window container) {
    Container parent = main;//w  ww .j a  v  a2s. c om
    Point parentLocation = parent.getLocationOnScreen();

    Dimension parentSize = parent.getSize();

    int calcedXLoc = (parentLocation.x) + ((parentSize.width) / 2) - (container.getWidth() / 2);
    int calcedYLoc = (parentLocation.y) + ((parentSize.height) / 2) - (container.getHeight() / 2);

    container.setVisible(true);
    container.setLocation(calcedXLoc, calcedYLoc);
    container.toFront();
    container.requestFocusInWindow();
}

From source file:org.notebook.gui.widget.GuiUtils.java

/**
 * Sets location of a window centered in main screen device. Window must
 * have size different of (0,0)//www  . j ava2  s  .c om
 * 
 * @param window
 */
public static void setLocation(Window window) {
    window.setLocation(mainDeviceBounds.width / 2 - window.getWidth() / 2,
            mainDeviceBounds.height / 2 - window.getHeight() / 2);
}

From source file:org.pgptool.gui.ui.tools.UiUtils.java

public static void centerWindow(Window frm) {
    Dimension scrDim = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (scrDim.width - frm.getSize().width) / 2;
    int y = (scrDim.height - frm.getSize().height) / 2;
    frm.setLocation(x, y);
}

From source file:tkwatch.Utilities.java

/**
 * Centers a frame on the screen; from Murach and Steelman, <i>Murach's Java
 * SE 6</i>, p. 487.//from   www.j a va2s . com
 * 
 * @param window
 *            The window to center.
 */
public static final void centerWindow(final Window window) {
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final Dimension dimension = toolkit.getScreenSize();
    window.setLocation((dimension.width - window.getWidth()) / 2, (dimension.height - window.getHeight()) / 2);
}