Java Swing How to - Control JOptionPane showInputDialog position








Question

We would like to know how to control JOptionPane showInputDialog position.

Answer

import javax.swing.JDialog;
import javax.swing.JOptionPane;
// www .  java2 s. c o m
public class Main {

  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);
    JDialog dialog = optionPane.createDialog(null, "TEST");
    dialog.setLocation(10, 20);
    dialog.setVisible(true);
    System.out.println(optionPane.getInputValue());

  }
}