Example usage for java.awt Container getLocationOnScreen

List of usage examples for java.awt Container getLocationOnScreen

Introduction

In this page you can find the example usage for java.awt Container 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:org.isatools.isacreatorconfigurator.configui.FieldInterface.java

private void showPopupInCenter(Window container) {
    Container parent = main;
    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);/* w  w w.  j a v  a2s.  c  o m*/
    container.setLocation(calcedXLoc, calcedYLoc);
    container.toFront();
    container.requestFocusInWindow();
}

From source file:phex.gui.common.FileDialogHandler.java

/**
 * @param chooser//from   www .j a v  a2 s . co m
 */
private static void displayNotificationPopup(JComponent chooser, String title, String shortMessage) {
    final SlideInWindow window = new SlideInWindow(title, 0);
    window.setShortMessage(shortMessage, true);
    window.setHideBtnShown(false);
    window.initializeComponent();
    window.setSize(200, 150);
    chooser.addAncestorListener(new AncestorListener() {
        public void ancestorAdded(AncestorEvent event) {
            window.setVisible(true);
        }

        public void ancestorRemoved(AncestorEvent event) {
            window.setVisible(false);
        }

        public void ancestorMoved(AncestorEvent event) {
            Container ancestor = event.getAncestor();
            Point loc = ancestor.getLocationOnScreen();
            int xPos = loc.x + ancestor.getWidth() + 5;
            int yPos = loc.y + ancestor.getHeight() - window.getHeight();
            window.setLocation(xPos, yPos);
        }

    });
}