JOptionPane showConfirmDialog with only one button

限于喜欢 提交于 2019-12-06 17:39:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!