Changing language in JFileChooser

Is there any way that I can change the language of the text in JFileChooser, ie, where it says File name and File type and such.Thanks for any help you can give me.
[185 byte] By [ndrw198] at [2007-9-26 3:22:06]
# 1

You could to this by calling javax.swing.UIManager.getDefaults(). That will retrieve a hashtable of the properties for the various UI components. Try printing out the various key/value properties and look for the properties related to the JFileChooser component. You should then be able to set these properties on the UIManager using the UIManager.put(Object key, Object value) method.

Hope this helps.

-David

Here's some code to illustrate that...

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

public class FileChooserDemo extends JFrame {

public FileChooserDemo() {

super("FileChooserDemo");

UIManager.put("FileChooser.acceptAllFileFilterText", "Show me all files");

UIManager.put("FileChooser.lookInLabelText", "Choose a path");

JFileChooser fileChooser = new JFileChooser();

this.getContentPane().add(fileChooser);

}

public static void main(String[] args) {

JFrame frame = new FileChooserDemo();

frame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {System.exit(0);}

});

frame.pack();

frame.setVisible(true);

}

}

> Is there any way that I can change the language of the

> text in JFileChooser, ie, where it says File name and

> File type and such.

>

> Thanks for any help you can give me.

CzarneckiD at 2007-6-29 11:39:32 > top of Java-index,Desktop,I18N...
# 2

Hi all,

in short this was an absolute mongrel to try and do under JDK1.3. I believe it's now slightly more configurable in 1.4, although still nothing to write home about. AFAIK, there is no easy way to change the file chooser's text through the UIManager in 1.3, so it's nigh on impossible. :(

Hope that helps,

Martin Hughes

martinhughes at 2007-6-29 11:39:32 > top of Java-index,Desktop,I18N...
# 3
Thanks a lot David, you code was a lot of help. Ive managed to change most labels now.Nick.
ndrw198 at 2007-6-29 11:39:32 > top of Java-index,Desktop,I18N...
# 4

Hi Nick,

out of interest, are you using Merlin Beta, or are you still in 1.3?

If you're still in 1.3, which labels did you manage to get to?

I've heard so many complaints about I18Ning the JFileChooser under 1.3 that I've avoided it like the plague, so I'd be interested in hearing exactly how much you can change.

Thanks!

Martin Hughes

martinhughes at 2007-6-29 11:39:32 > top of Java-index,Desktop,I18N...
# 5

I'm using 1.3, and I used Dave's code to figure out how to change the text, but to tell you the truth I just sort of guessed what the names of the variables that needed to be changed were.

Basically for say the Open button, it would be FileChooser.openButtonText, and it's ToolTipText is FileChooser.openButtonToolTipText. The New Folder button ToolTipText is FileChooser.newFolderToolTipText, and so on.

I didn't really need to change very much, so I wasn't very worried about going into it at depth.

Nick

ndrw198 at 2007-6-29 11:39:32 > top of Java-index,Desktop,I18N...
# 6
Ah, you were only changing the buttons and so forth, right?I believe most of the complaints have been against the title bar and the file list the FileChooser produces. Tho' I could be wrong. :)Thanks!Martin Hughes
martinhughes at 2007-6-29 11:39:32 > top of Java-index,Desktop,I18N...
# 7

There are 3 .properties files in the rt.jar file that you can translate, one for each look and feel.

You then create your Locale object and insert all the (key, value) pairs into the UIManager. That's it.

Some days ago I've posted one example of this in spanish. A LOT More tricky is translate the PrinterJob.printDialog() dialog, but you don't need that by now.

Gabriel

belingueres at 2007-6-29 11:39:32 > top of Java-index,Desktop,I18N...