I am using JOptionPane.showOptionDialog with the default "Yes", "No", and "Cancel" options.
When I press "Enter", the "Yes" option is activated, and when I press the "Tab" twice, it first selects the "No" button and then the "Cancel" button. However, even when the "No" or "Cancel" button is selected, pressing the "Enter" key still activates the "Yes" option, and not the "No", or "Cancel" cancel option.
I have 2 questions:
1) How can I correct this so that pressing the "Enter" key activates the selected option?
2) How can I find the "Yes", "No", and "Cancel" buttons in the JOptionPane class so that I can set the mnemonics?
Here is my code:
String message = "Do you want to save the Ananya Curves file before closing?";
int answer = JOptionPane.showOptionDialog(AnanyaCurves.this, message, "Close Ananya Curves",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
if (answer == JOptionPane.CLOSED_OPTION)
{
return;
}
else if (answer == JOptionPane.CANCEL_OPTION)
{
return;
}
else if (answer == JOptionPane.NO_OPTION)
{
//user wants to exit without saving
}
else if (answer == JOptionPane.YES_OPTION)
{
save();
}
//code for exit
Thanks for your time looking at this!