Java – how to change jooptionpane Default text for buttons in showinputdialog
•
Java
I want to be in joptionpane Set the text of OK and Cancel buttons in showinputdialog
There is a way to change joptionpane The button text in showoptiondialog, but I can't find a way to change it in showinputdialog
Solution
If you want to use the jooptionpane of the custom button text Showinputdialog, you can extend jooptionpane:
public class JEnhancedOptionPane extends JOptionPane { public static String showInputDialog(final Object message,final Object[] options) throws HeadlessException { final JOptionPane pane = new JOptionPane(message,QUESTION_MESSAGE,OK_CANCEL_OPTION,null,options,null); pane.setWantsInput(true); pane.setComponentOrientation((getRootFrame()).getComponentOrientation()); pane.setMessageType(QUESTION_MESSAGE); pane.selectInitialValue(); final String title = UIManager.getString("OptionPane.inputDialogTitle",null); final JDialog dialog = pane.createDialog(null,title); dialog.setVisible(true); dialog.dispose(); final Object value = pane.getInputValue(); return (value == UNINITIALIZED_VALUE) ? null : (String) value; } }
You can call it this:
JEnhancedOptionPane.showInputDialog("Number:",new Object[]{"Yes","No"});
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码