Swing/Locale のバックアップの現在との差分(No.9)
- category: swing folder: Locale title: JFileChooserにLocaleを設定する tags: [JFileChooser, Locale] author: aterai pubdate: 2008-01-07T12:38:12+09:00 description: JFileChooserにLocaleを設定して、タイトルやボタンの文字列を変更します。 image:
概要
JFileChooser
にLocale
を設定して、タイトルやボタンの文字列を変更します。
Screenshot
Advertisement
サンプルコード
#spandel
//JFileChooser.setDefaultLocale(Locale.ENGLISH);
#spanend
#spanadd
// JFileChooser.setDefaultLocale(Locale.ENGLISH);
#spanend
fileChooser.setLocale((Locale) combo.getSelectedItem());
#spandel
fileChooser.updateUI();
#spanend
#spanadd
SwingUtilities.updateComponentTreeUI(fileChooser);
#spanend
View in GitHub: Java, Kotlin解説
上記のサンプルでは、コンボボックスで指定したロケールをJFileChooser
に設定してから開くようになっています。
タイトル、ボタンのラベルなどが、指定したロケールに変更されます。
上記のサンプルでは、JFileChooser
のタイトル、ボタンのラベルなどを指定したLocale
に対応した文字列に変更するテストができます。
-
ファイルのタイプ(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)
としても反映されない
-
- 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
では再発している?
-