问题
I need to have only one button in showConfirmDialog
.
I tried this:
int response = JOptionPane.showConfirmDialog(null, "Time Entered Successfully",
"", JOptionPane.OK_OPTION, JOptionPane.PLAIN_MESSAGE);
if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.OK_OPTION)
{
System.out.println("CLOSING>>>>>>");
}
But this shows dialog with Yes_No_option.
I want only OK button to be displayed there. Is it possible?
回答1:
I want only OK button to be displayed there. Is it possible?
Use showOptionDialog() method.
Object[] options = {"OK"};
int n = JOptionPane.showOptionDialog(frame,
"Message here ","Title",
JOptionPane.PLAIN_MESSAGE,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
回答2:
try using this, it creates only one button
JOptionPane.showMessageDialog(null, "Loading Complete...!!!");
回答3:
It's the JOptionPane.DEFAULT_OPTION
JOptionPane.showConfirmDialog(null,
"MESSAGE",
"TITLE",
JOptionPane.DEFAULT_OPTION,
JOptionPane.PLAIN_MESSAGE);
来源:https://stackoverflow.com/questions/11204878/joptionpane-showconfirmdialog-with-only-one-button