赞
踩
如果要使用自定义按钮文本的JOptionPane.showInputDialog,可以扩展JOptionPane:
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;
}
}
你可以这样称呼:
JEnhancedOptionPane.showInputDialog("Number:", new Object[]{"Yes", "No"});
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。