Localizing the JFileChooser "All Files" string
Asked Answered
C

1

5

I am working on a java application with a JFileChooser and the user is able to switch languages.

Locale.setDefault( Locale.ENGLISH );
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog( null );

Locale.setDefault( Locale.CHINA );
JFileChooser.setDefaultLocale( Locale.CHINA );
JFileChooser chinese_chooser = new JFileChooser();
chinese_chooser.showOpenDialog( null );

The second file chooser to appear is in Chinese except for the "All Files" string in the drop down box. If I comment out the first section of code the file chooser appears correctly with all the strings translated.

Is this a bug in java or do I need to set the locale somewhere else?

How can I get the translated file chooser to appear correctly?

Colburn answered 11/6, 2013 at 17:55 Comment(0)
F
5

I found something that might help you here. Here's how you change the "All Files" string:

UIManager.put("FileChooser.acceptAllFileFilterText","abc4"); 

Just put this right before you set the default locale to Locale.CHINA. It's lame that it's not changed in the locale, but maybe that will give you the work around you need for this to work out for you.

Foment answered 11/6, 2013 at 18:5 Comment(2)
The String is included in the locale but for some reason it is not being updated. This worked for me: UIManager.put("FileChooser.acceptAllFileFilterText",UIManager.get( "FileChooser.acceptAllFileFilterText", Locale.CHINA ));Colburn
@Colburn it's a bug, indeed: the default fileFilter used by BasicFileChooserUI doesn't return the localized version of the string, see https://mcmap.net/q/2012453/-set-locale-properly-to-a-jfilechooserGrantee

© 2022 - 2024 — McMap. All rights reserved.