我的GUI程序中用到JOptionPane.showInputDialog和JOptionPane.showMessageDialog现在做多国语言化的时候出现麻烦,这两个对话框的按钮文本时跟随操作系统的,不能自由定义。我的意图并不是设置按钮的语言类型,而是改变按钮的文本。如果中文操作系统下是"确定" 、“取消”,改成“好”、“关闭”

解决方案 »

  1.   

    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) 
      

  2.   

    你自己写个对话框,照着API的构造函数自定义一下.就是了.
      

  3.   

    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
      

  4.   

    搞清楚了,修改UImanager的属性表
    贴出来,大家共享
    UIManager.put("OptionPane.titleText", "确认对话框");
    UIManager.put("OptionPane.yesButtonText", "好了");
    UIManager.put("OptionPane.noButtonText", "不行");
    UIManager.put("OptionPane.cancelButtonText", "关闭");
    JOptionPane.showConfirmDialog(null, "confirm");