vpJohan vpJohan - 1 year ago 63
Java Question

How do I get a specific responce when a JOptionPane is shut down by the cross in the upper right corner

Due to JOptionPanes being almost unusably buggy I tend to often get grey and empty panes which I close down by pressing the upper right corner.
When I do this the panes returns an anser Yes or No to my code whichI obviously do not want. How can I get my JOptionPanes to understand that it should reload the panel when I close it down?

Answer Source

Use one of the JOptionPane.showConfirmDialog() methods like they show here and here. The default optionType is Yes, No, Cancel, and the result will be CANCEL_OPTION if you click the winbdow's close button. If you're getting empty panes just sometimes, be sure to use the event dispatch thread from the begining of your program.