• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JFileChooserにLocaleを設定する
#navi(../)
*JFileChooserにLocaleを設定する [#d5c5fe75]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2008-01-07~
更新日:&lastmod;
---
category: swing
folder: Locale
title: JFileChooserにLocaleを設定する
tags: [JFileChooser, Locale]
author: aterai
pubdate: 2008-01-07T12:38:12+09:00
description: JFileChooserにLocaleを設定して、タイトルやボタンの文字列を変更します。
image: https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTPdRLH4_I/AAAAAAAAAeA/tZciS7a5CCc/s800/Locale.png
---
* 概要 [#summary]
`JFileChooser`に`Locale`を設定して、タイトルやボタンの文字列を変更します。

#contents
#download(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTPdRLH4_I/AAAAAAAAAeA/tZciS7a5CCc/s800/Locale.png)

**概要 [#z80ce7f3]
JFileChooserにLocaleを設定して、タイトルやボタンの文字列を変更します。

#screenshot

**サンプルコード [#o0d6f00f]
#code{{
//JFileChooser.setDefaultLocale(Locale.ENGLISH);
fileChooser.setLocale((Locale)combo.getSelectedItem());
fileChooser.updateUI();
* サンプルコード [#sourcecode]
#code(link){{
// JFileChooser.setDefaultLocale(Locale.ENGLISH);
fileChooser.setLocale((Locale) combo.getSelectedItem());
SwingUtilities.updateComponentTreeUI(fileChooser);
}}
-&jnlp;
-&jar;
-&zip;

**解説 [#h2e72623]
上記のサンプルでは、コンボボックスで指定したロケールをJFileChooserに設定してから開くようになっています。
タイトル、ボタンのラベルなどが、指定したロケールに変更されます。
* 解説 [#explanation]
上記のサンプルでは、`JFileChooser`のタイトル、ボタンのラベルなどを指定した`Locale`に対応した文字列に変更するテストができます。

- JDK 1.5.0_13 では、JVM のデフォルトが English 以外だった場合、Component#setLocale や、JComponent.setDefaultLocale を使っても反映されないようです。
-- [[Bug ID: 6606475 JComponent.setDefaultLocale(Locale.ENGLISH) useless if def locale is non-english>http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6606475]]
-- JDK 1.6.0 では問題無し
- `ファイルのタイプ(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, ...`」から変化しない

**参考リンク [#gbe40f72]
- [[Bug ID: 6606475 JComponent.setDefaultLocale(Locale.ENGLISH) useless if def locale is non-english>http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6606475]]
* 参考リンク [#reference]
- [https://bugs.openjdk.org/browse/JDK-6606475 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`では再発している?

**コメント [#h2cbdcae]
* コメント [#comment]
#comment
- メモ: [https://bugs.openjdk.org/browse/JDK-6342301 Bug ID: 6342301 Bad interaction between setting the ui and file filters in JFileChooser] -- &user(aterai); &new{2011-01-18 (火) 02:29:14};

#comment