16

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?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Shashank Degloorkar
  • 3,151
  • 4
  • 32
  • 50

3 Answers3

24

try using this, it creates only one button

JOptionPane.showMessageDialog(null, "Loading Complete...!!!");
Roman C
  • 49,761
  • 33
  • 66
  • 176
Viking
  • 241
  • 2
  • 3
20

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]);
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
16

It's the JOptionPane.DEFAULT_OPTION

JOptionPane.showConfirmDialog(null,
                "MESSAGE",
                "TITLE",
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.PLAIN_MESSAGE);
chromestone
  • 193
  • 1
  • 7