I have an option pane that is displayed upon closing my Application (windowClosing()).
I have the options to exit, minimize or cancel.
How can I close the option pane on selecting ‘cancel’ without closing the entire application?
Object[]options = {"Minimize", "Exit","Cancel"};
int selection = JOptionPane.showOptionDialog(
null, "Please select option", "Options", 0,
JOptionPane.INFORMATION_MESSAGE, null, options, options[1]);
System.out.println(selection);
switch(selection)
{
case 2:
{
// do something
}
}
You can call
yourFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);inside yourwindowClosing()method, if user chooses “cancel”….