Kashama Shinn
Kashama Shinn

Reputation: 241

How to change Yes/No option in confirmation dialog?

I want to change YES and NO to something like Agree/Disagree. What should I do?

int reply = JOptionPane.showConfirmDialog(null,
                                          "Are you want to continue the process?",
                                          "YES?",
                                          JOptionPane.YES_NO_OPTION);

Upvotes: 11

Views: 26780

Answers (5)

Aniket Thakur
Aniket Thakur

Reputation: 68905

You can do the following

JFrame frame = new JFrame();
String[] options = new String[2];
options[0] = "Agree";
options[1] = "Disagree";
JOptionPane.showOptionDialog(frame.getContentPane(), "Message!", "Title", 0, JOptionPane.INFORMATION_MESSAGE, null, options, null);

output is as follows

enter image description here

For more details about the showOptionDialog() function see here.

Upvotes: 31

sathya
sathya

Reputation: 1424

Try This!!

int res = JOptionPane.showConfirmDialog(null, "Are you want to continue the process?", "", JOptionPane.YES_NO_OPTION);
        switch (res) {
            case JOptionPane.YES_OPTION:
            JOptionPane.showMessageDialog(null, "Process Successfully");
            break;
            case JOptionPane.NO_OPTION:
            JOptionPane.showMessageDialog(null, "Process is Canceled");
            break;
        }

Upvotes: 2

Maxim Shoustin
Maxim Shoustin

Reputation: 77904

Try this one:

See JOptionPane documentation

JOptionPane(Object message, int messageType, int optionType,
        Icon icon, Object[] options, Object initialValue)

where options specifies the buttons with initialValue. So you can change them

Example

Object[] options = { "Agree", "Disagree" };

JOptionPane.showOptionDialog(null, "Are you want to continue the process?", "information",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
null, options, options[0]);

Upvotes: 3

Joachim Isaksson
Joachim Isaksson

Reputation: 180867

You can use the options parameter to push custom options to showOptionDialog;

Object[] options = { "Agree", "Disagree" };
JOptionPane.showOptionDialog(null, "These are my terms", "Terms",
    JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, 
    options, options[0]);

Upvotes: 7

Joban
Joban

Reputation: 1337

You might want to checkout JOptionPane.showOptionDialog, that will let you push in a text parameter (in array form).

Upvotes: 3

Related Questions