Example usage for java.awt Window getLocationOnScreen

List of usage examples for java.awt Window getLocationOnScreen

Introduction

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

Prototype

public Point getLocationOnScreen() 

Source Link

Document

Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.

Usage

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 ww .  ja v  a2s. c  om*/
}

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 ww  w  . j a va  2s .  c om*/
}

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 ww  . j  a  v 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 a component according to the window location.
 * @param wnd The parent window/*from   w w  w . j  av  a  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

/**
 * Zentriert ein Window relativ zu dem Parent-Window
 * // w  ww  . j  av  a 2  s  . c o m
 * @param parent
 *            Parent-Window, wenn null, dann wird relativ zu dem Bildschirm
 *            zentriert
 * @param child
 *            Window das zentrirt werden soll.
 */
static public void centreWindow(Window parent, Window child) {
    if (child == null)
        return;
    Point parentLocation = null;
    Dimension parentSize = null;
    if (parent == null) {
        parentLocation = new Point(0, 0);
        parentSize = child.getToolkit().getScreenSize();
    } else {
        parentLocation = parent.getLocationOnScreen();
        parentSize = parent.getSize();
    }
    Dimension childSize = child.getSize();
    child.setLocation((int) (parentLocation.getX() + parentSize.getWidth() / 2 - childSize.getWidth() / 2),
            (int) (parentLocation.getY() + parentSize.getHeight() / 2 - childSize.getHeight() / 2));
}

From source file:net.pandoragames.far.ui.swing.dialog.SubWindow.java

/**
 * Positions this FileWindow on the screen. The position is choosen with respect to
 * the specified screen center, the position of the owner and the position of the last 
 * visible subwindow of the owner, if any.
 * @param screenCenter coordinates of the screen center
 *//*from ww  w.  j  a v  a2  s  .  co  m*/
protected void placeOnScreen(Point screenCenter) {
    Window parent = getOwner();
    Point indent = parent.getLocationOnScreen();
    Point leftUpper = new Point(200, 50);
    Window sister = getLatestPeer();
    if (sister != null) {
        try {
            leftUpper = sister.getLocationOnScreen();
            indent = new Point(25, 25);
        } catch (IllegalComponentStateException icsx) {
            leftUpper = new Point(screenCenter);
        }
    }
    //      
    //      Window[] peers = parent.getOwnedWindows();
    //      if( peers.length > 1 ) {
    //         int count = peers.length -2;
    //         Window sister = null;
    //         do {
    //            sister = peers[count];
    //            count--;
    //         } while ((count >= 0) 
    //                     && ((sister == null) || (! sister.isShowing())));
    //         if((sister != null) && (sister.isShowing())) {
    //            try {
    //               leftUpper = sister.getLocationOnScreen();
    //               indent = new Point(25,25);
    //            } catch (IllegalComponentStateException icsx) {
    //               leftUpper = new Point(screenCenter);
    //            }
    //         }
    //      } 
    if (leftUpper == null) {
        logger.warn("Location was null, using screen center");
        leftUpper = new Point(screenCenter);
    }
    if (leftUpper.x > screenCenter.x)
        indent.x = -indent.x;
    if (leftUpper.y > screenCenter.y)
        indent.y = -indent.y;
    setLocation(leftUpper.x + indent.x, leftUpper.y + indent.y);
}

From source file:corelyzer.ui.CorelyzerApp.java

public void relocateToolMenu(final int id) {
    Point p;/*from  w  w  w  .j  a v a2 s . com*/
    Window jf;
    jf = windowVec.elementAt(id);
    if ((jf != null) && jf.isVisible()) {
        p = jf.getLocationOnScreen();

        // Dimension screenDim =
        // Toolkit.getDefaultToolkit().getScreenSize();
        int canvasWidth = preferences().screenWidth;
        Dimension toolFrameDim = toolFrame.getSize();
        p.x += canvasWidth / 2 - toolFrameDim.width / 2;

        toolFrame.setLocation(p.x, p.y);
    }
}

From source file:org.apache.cayenne.modeler.util.CayenneController.java

/**
 * Centers view on parent window.//from   w w w. j  a va  2  s  .c  o  m
 */
protected void centerView() {
    Window parentWindow = parent.getWindow();

    Dimension parentSize = parentWindow.getSize();
    Dimension windowSize = getView().getSize();
    Point parentLocation = new Point(0, 0);
    if (parentWindow.isShowing()) {
        parentLocation = parentWindow.getLocationOnScreen();
    }

    int x = parentLocation.x + parentSize.width / 2 - windowSize.width / 2;
    int y = parentLocation.y + parentSize.height / 2 - windowSize.height / 2;

    getView().setLocation(x, y);
}