【发布时间】:2011-05-24 15:25:22
【问题描述】:
可能重复:
How to use UTF-8 in resource properties with ResourceBundle
我想允许我的 Java Swing 应用程序国际化。我使用捆绑文件将所有标签保存在其中。
作为测试,我尝试将瑞典语标题设置为 JButton。所以在我写的包文件中:
nextStepButton=nästa
在我写的Java代码中:
nextStepButton.setText(bundle.getString("nextStepButton"));
但按钮的标题字符在运行时出现错误:
我正在使用支持 Unicode 的 Tahoma 字体。 当我通过代码手动设置按钮标题时,它看起来很好:
nextStepButton.setText("nästa");
知道为什么它在捆绑文件中失败了吗?
------------------------------> 编辑:对标题进行编码:
我尝试使用以下代码对来自捆绑文件的文本进行编码:
nextStepButton.setText(new String(bundle.getString("nextStepButton").getBytes("UTF-8")));
结果仍然是:
【问题讨论】:
-
也许你的捆绑文件编码不正确?
-
如何创建属性文件?
-
我使用 Eclipse ...我从 Eclipse 内部创建属性文件作为普通文本文件 + 我将其编码设置为“UTF-8”。
标签: java swing internationalization resourcebundle mojibake