Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change language of JFileChooser-Dialog

1,710 views
Skip to first unread message

Matthias Weise

unread,
Mar 6, 2003, 3:58:57 AM3/6/03
to
Hello,

I want to support different languages in my Java application.
For selecting files I use JFileChooser, which seems to use the language
defined for the underlying operating system.
I tried to change it with the methode setLocale(Locale l) inherited from
java.awt.Component. But it doesn't work.

What's wrong? I assume there is a way to switch between languages. If not,
how can I change all the text messages 'manually'? (I found some methodes to
do that, for example chooser.setApproveButtonText("Open"). May I am wrong
but I think there are not enough such methodes to change all messages.)

Thank's in advance,
Matthias


JFileChooser chooser = new JFileChooser();
chooser.setLocale(Locale.ENGLISH);
int returnVal = chooser.showOpenDialog(this);

Harald Hein

unread,
Mar 6, 2003, 4:49:20 AM3/6/03
to
"Matthias Weise" wrote:

> I want to support different languages in my Java application.
> For selecting files I use JFileChooser, which seems to use the
> language defined for the underlying operating system.
> I tried to change it with the methode setLocale(Locale l)
> inherited from java.awt.Component. But it doesn't work.

This has been discussed a lot in this group. You need to set some
properties. See old postings for the details.

HH

Matthias Weise

unread,
Mar 6, 2003, 5:31:47 AM3/6/03
to
I have access to less than 400 postings in this group. In these postings I
did not found something dealing with JFileChooser.
Can anyone forward such posting to me?

Matthias

"Harald Hein" <speec...@gmx.de> schrieb im Newsbeitrag
news:Xns93366E1A...@194.97.5.9...

Tom

unread,
Mar 6, 2003, 7:25:28 AM3/6/03
to
Try this - I did it for polish localization:

public void buildMainWindow() {
try {
Locale myLocale = Locale.getDefault();


////////////////////////////////////////////////////////////////////////////
/////
// Default locale is english, if there is polish we need to
change JFileChooser
// Java doesn't allow for easy changes of JFileChooser so this
is quick hack
if (myLocale.getLanguage().equals("pl")) {
UIManager.put("FileChooser.openButtonText","Otwórz");
UIManager.put("FileChooser.cancelButtonText","Anuluj");
UIManager.put("FileChooser.saveButtonText","Zapisz");
UIManager.put("FileChooser.cancelButtonToolTipText",
"Anulowanie operacji");
UIManager.put("FileChooser.saveButtonToolTipText", "Zapis
danych do pliku");
UIManager.put("FileChooser.openButtonToolTipText", "Przejdz
do katalogu");

UIManager.put("FileChooser.lookInLabelText", "Szukaj w :");
UIManager.put("FileChooser.fileNameLabelText", "Plik:");
UIManager.put("FileChooser.filesOfTypeLabelText", "Pliki
typu:");
UIManager.put("FileChooser.upFolderToolTipText", "Do góry");
UIManager.put("FileChooser.homeFolderToolTipText", "Glówny
pulpit");
UIManager.put("FileChooser.newFolderToolTipText", "Nowy
folder");
UIManager.put("FileChooser.listViewButtonToolTipText",
"Lista");
UIManager.put("FileChooser.detailsViewButtonToolTipText",
"Szczególy");
}
}


Thomas Kellerer

unread,
Mar 6, 2003, 7:45:06 AM3/6/03
to
Start your jvm with

java -Duser.langauge=en myMainClass

JFileChooser uses the languaged specified by this propeterty. Setting the
property at runtime will not work.

Thomas


Matthias Weise schrieb:

Matthias Weise

unread,
Mar 6, 2003, 8:23:46 AM3/6/03
to
Great thanks, it works fine!

By the way I have translations for polish, so I consider to support polish
as well :-)

Best wishes,
Matthias


Matthias Weise

unread,
Mar 6, 2003, 8:26:16 AM3/6/03
to
Thanks for your valuable comment,
Matthias


Harald Hein

unread,
Mar 6, 2003, 6:46:46 PM3/6/03
to
"Matthias Weise" wrote:

> I have access to less than 400 postings in this group.

Learn to use groups.google.com

HH

0 new messages