I want to set the text of OK and CANCEL buttons in JOptionPane.showInputDialog
to my own strings.
There is a way to change the buttons' text in JOptionPane.showOptionDialog
, but I couldn't find a way to change it in showInputDialog
.
When I ask a user to enter a quantity for a program I have made using the code below, the default text is 3. String input = JOptionPane.
There is an easy way to change the default font in JOptionPane . Pass a string modified in html format, which means you can either use <font> tag or even CSS. Using <font> tag. Using CSS.
showOptionDialog( panel, "Choose one of the following options for Category " + category + ". \n" + "If skip is available, you may choose it to skip this category.", "Select option", optionType, JOptionPane. INFORMATION_MESSAGE, null, options, options[0]);
The code below should make a dialog appear and you can specify the button text in the Object[]
.
Object[] choices = {"One", "Two"};
Object defaultChoice = choices[0];
JOptionPane.showOptionDialog(this,
"Select one of the values",
"Title message",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
choices,
defaultChoice);
Also, make sure to look through the Java tutorials on the Oracle site. I found the solution at this link in the tutorials http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#create
if you don't want it for just a single inputDialog, add these lines prior to creating dialog
UIManager.put("OptionPane.cancelButtonText", "nope");
UIManager.put("OptionPane.okButtonText", "yup");
where 'yup' and 'nope' is the text you want displayed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With