11

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);
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Kashama Shinn
  • 241
  • 2
  • 4
  • 11
  • 1
    [as obviously everything is Oracle tutorial](http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#button) – mKorbel Aug 17 '13 at 07:02

5 Answers5

31

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.

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • Yes this is working as expected, but is there a way to change font of "Agree" and "Disagree" buttons?. I want to internationalize my application. – Disapamok May 16 '17 at 11:52
7

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]);
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • It work and change for JOptionPane.showOptionDialog but I want to change for JOptionPane.showConfirmDialog Is it the same way or not? – Kashama Shinn Aug 17 '13 at 08:35
3

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

Joban
  • 1,318
  • 7
  • 19
3

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]);
Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
2

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;
        }
sathya
  • 1,404
  • 2
  • 15
  • 26