Reputation: 601
I wonder if there is a way to change the default joptions pane buttons strings instead of say "ok" and "cancel" to say something other like "option1" and "option2". Thank you!
Upvotes: 1
Views: 151
Reputation: 29166
From the documentation -
Object[] options = { "Option 1", "Option 2", "Option 3" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "My Title",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);
The above code -
Show a warning dialog with the options Option 1, Option 2, Option 3, title My Title, and message Click OK to continue.
For more information, you can take a look at this tutorial.
Upvotes: 3
Reputation: 8101
Yes there is a way to do that...Have a look here....
String[] options = new String[] {"op1", "op2", "op3"};
JOptionPane.showOptionDialog(null, "Options", "Hi there",
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);
Upvotes: 2
Reputation: 15834
This works for me
String[] choices = { "Option 1", "Option 2", "Option 3", "Option 4" };
int response = JOptionPane.showOptionDialog(null, "Dialog text",
"Title", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null, choices, null);
System.out.println(response);
It returns 0-3
(chosen option) or -1
if you cancel the dialog.
Upvotes: 3