Shashank Degloorkar
Shashank Degloorkar

Reputation: 3221

JOptionPane showConfirmDialog with only one button

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?

Upvotes: 17

Views: 39985

Answers (3)

chromestone
chromestone

Reputation: 203

It's the JOptionPane.DEFAULT_OPTION

JOptionPane.showConfirmDialog(null,
                "MESSAGE",
                "TITLE",
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.PLAIN_MESSAGE);

Upvotes: 16

Viking
Viking

Reputation: 241

try using this, it creates only one button

JOptionPane.showMessageDialog(null, "Loading Complete...!!!");

Upvotes: 24

KV Prajapati
KV Prajapati

Reputation: 94625

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]);

Upvotes: 21

Related Questions