Reputation: 241
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
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
For more details about the showOptionDialog() function see here.
Upvotes: 31
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
Reputation: 77904
Try this one:
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
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
Reputation: 1337
You might want to checkout JOptionPane.showOptionDialog
, that will let you push in a text parameter (in array form).
Upvotes: 3