7

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.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?

4 Answers 4

8

You can specify language when you start the VM.

java -Duser.language=en -Duser.country=US -Duser.variant=US MainClass

Sign up to request clarification or add additional context in comments.

1 Comment

For testing a translation (ResourceBundle), this works great on Windows. Thanks!
6

You have to set the locale via JComponent.setDefaultLocale() before cou create the JFileChooser object.

5 Comments

'JFileChooser chooser = new JFileChooser(); chooser.setDefaultLocale(Locale.ENGLISH); chooser.setLocale(Locale.ENGLISH);'
Sounds reasonable - I wouldn't expect an API that allows to change the locale of an awt or swing component anyway - that a very rare use case and terribly difficult to implement ;)
@Mr Zen - you actually haven't tried. Michaels suggestion is based on a static method in JComponent ;)
@Andreas... here's my code that works now..' this.setDefaultLocale(Locale.ENGLISH); JFileChooser chooser = new JFileChooser();' Thanks for the interest anyways (+1)
@Andreas_D: since JFileChooser is a subclass of JComponent and static methods can be called on instances in Java, he did call the correct method, just not at the right time.
4

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.

7 Comments

My JFilechooser's button's OK/CANCEL are showing in Japanese. I'm using Japanese Windows. How to change that to English?
If the application is localized changing your PC locale should be sufficient.
@Simeon. Changing the PC locale is a bad advice. It will affect all applications on the OS.
@Kaj hardcoding a locale setting is worse IMO, as they might forget they did it and this could lead to all kinds of messes. Also I think that if he prefers using his swing app in English, he will have the same preference for other apps.
@Simeon I haven't said that he should hardcode. See my answer, I suggested using VM arguments.
|
1

You can make it work with the code below but the JComponent locale is a better option.

JFileChooser chooser = new JFileChooser();
chooser.setLocale(Locale.getDefault());
chooser.updateUI();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.