Example usage for javax.swing JDialog getLocation

List of usage examples for javax.swing JDialog getLocation

Introduction

In this page you can find the example usage for javax.swing JDialog getLocation.

Prototype

public Point getLocation() 

Source Link

Document

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

Usage

From source file:Main.java

public static void setCenterOfParent(JDialog parent, JDialog dialog) {
    Point parentPosition = parent.getLocation();
    Dimension parentSize = parent.getSize();
    Dimension size = dialog.getSize();
    Point position = new Point(parentPosition.x + (parentSize.width / 2 - size.width / 2),
            parentPosition.y + (parentSize.height / 2 - size.height / 2));
    dialog.setLocation(position);//from   w w  w.ja  v a  2 s .c  o  m
}

From source file:net.lmxm.ute.gui.validation.AbstractInputValidator.java

/**
 * Display messages dialog.// www. ja  va 2  s . c om
 * 
 * @param component the component
 * @param messages the messages
 */
private void displayMessagesDialog(final JComponent component, final List<String> messages) {
    final JDialog dialog = getMessagesDialog();

    // Load dialog with messages.
    getMessagesLabel().setText(StringUtils.join(messages, "\n"));

    // Relocate dialog relative to the input component
    dialog.setSize(0, 0);
    dialog.setLocationRelativeTo(component);
    final Point location = dialog.getLocation();
    final Dimension componentSize = component.getSize();
    dialog.setLocation(location.x - (int) componentSize.getWidth() / 2,
            location.y + (int) componentSize.getHeight() / 2);
    dialog.pack();
    dialog.setVisible(true);
}