Example usage for javax.swing JDialog setLocation

List of usage examples for javax.swing JDialog setLocation

Introduction

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

Prototype

@Override
public void setLocation(int x, int y) 

Source Link

Document

The method changes the geometry-related data.

Usage

From source file:Main.java

public static void main(String... args) {
    JOptionPane optionPane = new JOptionPane("Its me", JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION,
            null, null, "Please ENTER your NAME here");
    optionPane.setWantsInput(true);/*from  w  ww  .  j  av  a 2  s  .  com*/
    JDialog dialog = optionPane.createDialog(null, "TEST");
    dialog.setLocation(10, 20);
    dialog.setVisible(true);
    System.out.println(optionPane.getInputValue());

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JDialog dialog = new JDialog(frame, false);
    dialog.setSize(200, 50);/*www .ja va2s .  co m*/
    frame.addComponentListener(new ComponentAdapter() {
        Point lastLocation;

        @Override
        public void componentMoved(ComponentEvent e) {
            if (lastLocation == null && frame.isVisible()) {
                lastLocation = frame.getLocation();
            } else {
                Point newLocation = frame.getLocation();
                int dx = newLocation.x - lastLocation.x;
                int dy = newLocation.y - lastLocation.y;
                dialog.setLocation(dialog.getX() + dx, dialog.getY() + dy);
                lastLocation = newLocation;
            }
        }
    });
    frame.setSize(400, 200);
    frame.setVisible(true);
    dialog.setLocationRelativeTo(frame);
    dialog.setVisible(true);
}

From source file:Main.java

public static void centerFrame(JDialog jd) {

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = jd.getSize();
    jd.setLocation((screenSize.width / 2) - (frameSize.width / 2),
            (screenSize.height / 2) - (frameSize.height / 2));
}

From source file:Main.java

/**
 * This method centers the given dialog.
 *
 * @param  dDialog  The dialog to center.
 *//* w w  w.  j a va  2 s  .c o  m*/
public static void centerDialog(JDialog dDialog) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension labelSize = dDialog.getSize();
    dDialog.setLocation((screenSize.width / 2) - (labelSize.width / 2),
            (screenSize.height / 2) - (labelSize.height / 2));
}

From source file:Main.java

/**
 * Center JDialog./*from w w  w.  ja v  a 2  s .c o m*/
 */
public static void center(JDialog dialog) {
    Dimension dialogSize = dialog.getSize();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    dialog.setLocation((screenSize.width - dialogSize.width) >> 1,
            (screenSize.height - dialogSize.height) >> 1);
}

From source file:Main.java

/**
 * Used to centre the dialogs./*w w  w.j  a  va 2  s .c  o m*/
 */
public static void centreOnParent(final JDialog dialog, final JFrame frame) {
    int x = frame.getX();
    x += (frame.getWidth() - dialog.getWidth()) / 2;

    int y = frame.getY();
    y += (frame.getHeight() - dialog.getHeight()) / 2;

    dialog.setLocation(x, y);
}

From source file:Main.java

public static void showDialog(JDialog d) {
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final Dimension screenSize = toolkit.getScreenSize();
    final int x = (screenSize.width - d.getWidth()) / 2;
    final int y = (screenSize.height - d.getHeight()) / 2;
    d.setLocation(x, y);
    d.setVisible(true);// ww  w .j ava  2 s  .com
}

From source file:Main.java

/**
 * Centers JDialog on screen//from  ww w. j a v a 2  s . c  o m
 *
 * @param target
 */
public static void centerDialog(final JDialog target) {
    final Rectangle screen = getScreenRect();
    final Rectangle frameSize = target.getBounds();
    final int x = (screen.width - frameSize.width) / 2;
    final int y = (screen.height - frameSize.height) / 2;
    target.setLocation(x, y);
}

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 source file:Main.java

/**
 * Resize a dialog to be a percentage of the total screen size
 * //w w  w.j  a v  a 2 s  .com
 * @param owner
 * @param dialog
 * @param percentage
 */
public static void resizeAndCentreDialogOnScreen(JDialog dialog, double percentage) {
    Dimension screenSize = toolkit.getScreenSize();
    int width = (int) ((screenSize.width * percentage) / 100d);
    int height = (int) ((screenSize.height * percentage) / 100d);

    dialog.setSize(width, height);
    int x = (int) ((screenSize.width * 0.5f) - (width * 0.5f));
    int y = (int) ((screenSize.height * .05f) - (height * 0.5f));
    dialog.setLocation(x, y);
}