Search code examples
javaswingdialogjoptionpane

Closing JDialog Java


How can I stop dialog box running?

String menuInput = null;
        JOptionPane askOpenOrNew = new JOptionPane(
                "Would you like to Open a save\nor create a New world?");
        Object[] askOptions = new String[] { "Open World", "New World",
                "Cancel" };
        askOpenOrNew.setOptions(askOptions);
        JDialog askDialog = askOpenOrNew.createDialog(new JFrame(),
                "There is no World");
        askDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        askDialog.setVisible(true);

It keeps the console in Eclipse running after the program, should have, terminated.

EDIT: The dialog box does close (In that it disappears from screen) but the console doesn't terminate unless explicitly told (System.exit(0)).


Solution

  • If you want the program to exit, I'd recommend explicitly calling System.exit(0)