Swing/Locale のバックアップの現在との差分(No.2)
TITLE:JFileChooserにLocaleを設定する
JFileChooserにLocaleを設定する
編集者:Terai Atsuhiro~
作成日:2008-01-07
更新日:2021-06-02 (水) 12:17:58
概要
JFileChooser
にLocale
を設定して、タイトルやボタンの文字列を変更します。
Screenshot
Advertisement
概要
JFileChooserにLocaleを設定して、タイトルやボタンの文字列を変更します。#screenshot
サンプルコード
#spanend
#spandel
//JFileChooser.setDefaultLocale(Locale.ENGLISH);
#spanend
#spandel
fileChooser.setLocale((Locale)combo.getSelectedItem());
#spanend
#spandel
fileChooser.updateUI();
#spanend
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
#spanadd
// JFileChooser.setDefaultLocale(Locale.ENGLISH);
#spanend
#spanadd
fileChooser.setLocale((Locale) combo.getSelectedItem());
#spanend
#spanadd
SwingUtilities.updateComponentTreeUI(fileChooser);
#spanend
- &jar;
- &zip;
解説
上記のサンプルでは、コンボボックスで指定したロケールをJFileChooserに設定してから開くようになっています。 タイトル、ボタンのラベルなどが、指定したロケールに変更されます。解説
上記のサンプルでは、JFileChooser
のタイトル、ボタンのラベルなどを指定したLocale
に対応した文字列に変更するテストができます。
- JDK 1.5.0_13 では、JVM のデフォルトが English 以外だった場合、Component#setLocale や、JComponent.setDefaultLocale を使っても反映されないようです。
-
ファイルのタイプ(T): JComboBox
の「すべてのファイル」などは更新されない-
java -Duser.language=fr -jar example.jar
で起動するとLocale
を変更してもTous les fichiers
から変化しない
-
- 詳細表示
JTable
のヘッダは更新されない-
JDK 8
ではjava -Duser.language=fr -jar example.jar
で起動しても「名前、サイズ、項目の種類、更新日時」などOS
が使用しているロケール?から文字列が取得される? -
JDK 13
ではjava -Duser.language=fr -jar example.jar
で起動するとLocale
を変更しても「Nom, Taille, ...
」から変化しない
-
参考リンク
参考リンク
- Bug ID: 6606475 JComponent.setDefaultLocale(Locale.ENGLISH) useless if def locale is non-english
-
JDK 1.5.0_13
では、JVM
のデフォルトがEnglish
以外の場合、Component#setLocale(Locale.ENGLISH)
や、JComponent.setDefaultLocale(Locale.ENGLISH)
としても反映されない -
JDK 1.6.0
で修正済み -
JDK 1.8.0
では再発している?
-