You can use the JOptionPane method setLocation (...) . OR Instead of using JOptionPane you can extend the JDialog and then specify its location on the screen.
Here is one working code example recommended by @HovercraftFullOfEels, only this example will help you get user input for your request:
import javax.swing.*; public class OptionPaneLocation { private void createAndDisplayGUI() { 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()); } public static void main(String... args) { Runnable runnable = new Runnable() { public void run() { new OptionPaneLocation().createAndDisplayGUI(); } }; SwingUtilities.invokeLater(runnable); } }
nIcE cOw
source share