日期:2014-05-20  浏览次数:20788 次

如何自定义JOptionPane.showInputDialog输入对话框的按钮文本
我的GUI程序中用到JOptionPane.showInputDialog和JOptionPane.showMessageDialog

现在做多国语言化的时候出现麻烦,这两个对话框的按钮文本时跟随操作系统的,不能自由定义。

我的意图并不是设置按钮的语言类型,而是改变按钮的文本。如果中文操作系统下是"确定" 、“取消”,改成“好”、“关闭”

------解决方案--------------------
最好的方式就是去读源代码,然后找到对应的控件,然后做相应修改。
------解决方案--------------------
showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) 

showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) 

------解决方案--------------------
探讨
showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)

showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue)


------解决方案--------------------
根据你的要求,只能是自定义对话框了.并且自定义对话框也不是难事.
------解决方案--------------------
你自己写个对话框,照着API的构造函数自定义一下.就是了.
------解决方案--------------------
Java code


Object[] options = { "好", "关闭" };
int n = JOptionPane.showOptionDialog(null,
"Would you like green eggs and ham?",
"A Silly Question",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, 
null, // do not use a custom Icon
options, // the titles of buttons
options[0]); // default button title