Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 816
Kashama Shinn Avatar asked Aug 17 '13 06:08

Kashama Shinn


4 Answers

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]);
like image 142
Joachim Isaksson Avatar answered Nov 16 '22 10:11

Joachim Isaksson


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.

like image 44
Aniket Thakur Avatar answered Nov 16 '22 09:11

Aniket Thakur


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

like image 31
Joban Dhillon Avatar answered Nov 16 '22 11:11

Joban Dhillon


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]);
like image 3
Maxim Shoustin Avatar answered Nov 16 '22 09:11

Maxim Shoustin