Is it possible to call a confirmation dialog, that would have ONLY YES
and NO
options (without the CANCEL option)?
JOptionPane.showConfirmDialog(null, "Are you sure?")
Gives three options, but I need only two.
Is it possible to call a confirmation dialog, that would have ONLY YES
and NO
options (without the CANCEL option)?
JOptionPane.showConfirmDialog(null, "Are you sure?")
Gives three options, but I need only two.
Yes. it is possible.
int result = JOptionPane.showConfirmDialog(null,
"Are you sure you wish to exit application?",null, JOptionPane.YES_NO_OPTION);
if(result == JOptionPane.YES_OPTION) {
System.exit(0);
}
Try using the other Overload method of JOption.showConfirmDialog method. that takes optionType
. You can pass YES_NO_OPTION
, YES_NO_CANCEL_OPTION
, or OK_CANCEL_OPTION
option types.
JOptionPane.showConfirmDialog(null, "Are you sure?", "Message",
JOptionPane.YES_NO_OPTION);
You can use the other showConfirmDialog
where you can specify the optionType
.
JOptionPane.showConfirmDialog(null, "Test", "Test1", JOptionPane.YES_NO_OPTION);
From the docs:-
Brings up a dialog where the number of choices is determined by the optionType parameter.
You can use: int answer = JOptionPane.showConfirmDialog(null, "Are you sure question?", "titleToYouMessageBox", JOptionPane.YES_NO_OPTION);