java 如何在Java中设置语言?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6305087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set language in Java?
提问by Mr. Zen
I am using a Java program with foreign operating system (Korean/Japanese etc.) The display of swing components such as FileChooser is in the foreign langauges, which I need to change to English.
我使用的是国外操作系统的Java程序(韩文/日文等)。Swing组件如FileChooser的显示是外文,需要改成英文。
java.util.Locale.setDefault(java.util.Locale.ENGLISH);
JFileChooser chooser = new JFileChooser();
chooser.setLocale(Locale.ENGLISH);
And the file chooser still shows everything - buttons etc. in these foreign langauges. Any idea how to fix it?
并且文件选择器仍然显示所有内容 - 这些外语中的按钮等。知道如何修复它吗?
My JFilechooser's button's OK/CANCEL are showing in Japanese. I'm using Japanese Windows. How to change that to English?
我的 JFilechooser 按钮的 OK/CANCEL 显示为日语。我正在使用日语 Windows。怎么改成英文?
回答by Kaj
You can specify language when you start the VM.
您可以在启动 VM 时指定语言。
java -Duser.language=en -Duser.country=US -Duser.variant=US MainClass
java -Duser.language=en -Duser.country=US -Duser.variant=US MainClass
回答by Michael Borgwardt
You have to set the locale via JComponent.setDefaultLocale()
beforecou create the JFileChooser
object.
在创建对象之前,您必须通过设置语言环境。JComponent.setDefaultLocale()
JFileChooser
回答by duffymo
I don't mean to point out the obvious, but it's hard to tell what your expectations are based on the code you posted. Merely changing locale won't modify the Unicode characters you send to the UI; it won't translate from one language to another, either. Changing Locale is necessary but not sufficient.
我并不是要指出显而易见的事情,但很难根据您发布的代码判断您的期望是什么。仅仅改变语言环境不会修改你发送到 UI 的 Unicode 字符;它也不会从一种语言翻译成另一种语言。更改区域设置是必要的,但还不够。
回答by Jonathan Drapeau
You can make it work with the code below but the JComponent locale is a better option.
您可以使用下面的代码使其工作,但 JComponent 语言环境是更好的选择。
JFileChooser chooser = new JFileChooser();
chooser.setLocale(Locale.getDefault());
chooser.updateUI();