JOptionPane showConfirmDialog只有一个按钮

Sha*_*kar 15 java swing joptionpane

我只需要一个按钮showConfirmDialog.

我试过这个:

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>>>>>>");
}
Run Code Online (Sandbox Code Playgroud)

但是这显示了Yes_No_option的对话框.

我只想在那里显示OK按钮.可能吗?

小智 22

尝试使用它,它只创建一个按钮

JOptionPane.showMessageDialog(null, "Loading Complete...!!!");
Run Code Online (Sandbox Code Playgroud)


ada*_*ost 19

我只想在那里显示OK按钮.可能吗?

使用showOptionDialog()方法.

    Object[] options = {"OK"};
    int n = JOptionPane.showOptionDialog(frame,
                   "Message here ","Title",
                   JOptionPane.PLAIN_MESSAGE,
                   JOptionPane.QUESTION_MESSAGE,
                   null,
                   options,
                   options[0]);
Run Code Online (Sandbox Code Playgroud)


小智 11

就是这样 JOptionPane.DEFAULT_OPTION

JOptionPane.showConfirmDialog(null,
                "MESSAGE",
                "TITLE",
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.PLAIN_MESSAGE);
Run Code Online (Sandbox Code Playgroud)