TITLE:JFileChooserのボタンテキストを変更
#navi(../)
RIGHT:Posted by [[aterai]] at 2008-10-20
*JFileChooserのボタンテキストを変更 [#q32fca17]
JFileChooserのボタンテキストを変更します。

//-&jnlp;
-&jar;
-&zip;

//#screenshot
#ref(http://lh4.ggpht.com/_9Z4BYR88imo/TQTHw6_sLrI/AAAAAAAAARs/5fsN5G2p15U/s800/ApproveButtonText.png)

**サンプルコード [#b602fe55]
#code{{
//UIManager.put("FileChooser.saveButtonText",   "保存(S)");
//UIManager.put("FileChooser.openButtonText",   "開く(O)");
UIManager.put("FileChooser.cancelButtonText", "キャンセル");

JFileChooser fileChooser = new JFileChooser();
//fileChooser.setApproveButtonText("開く(O)");
//fileChooser.setApproveButtonMnemonic('O');
}}

**解説 [#d57fefff]
上記のサンプルは、日本語のWindowsLnFに合わせてJFileChooserのApproveButtonやキャンセルボタンのテキストを以下のように変更しています。

-%%OpenDialogのデフォルトでは、ファイルリストでフォルダが選択されていると「開く(O)」、ファイルが選択されていると「開く」で切り替わるとボタンサイズが変化してしまうため、「開く(O)」に揃える%%
-%%SaveDialogのデフォルトでは、ファイルリストでフォルダが選択されていると「開く(O)」、ファイルが選択されていると「保存」なので、「保存(S)」に揃える%%
--CancelButtonのデフォルトは、「取消し」でSaveDialogのフォルダ・ファイルの選択が切り替わるとボタンサイズが変化するので、二文字分長い「キャンセル」に変更

//**参考リンク
**コメント [#m3d63c30]
- 1.6.0_12 以降、デフォルトではMnemonicの表示がなくなっているようです(もしかしてバグだった?)。 -- [[aterai]] &new{2009-10-09 (金) 20:01:14};
-- メモ: [[Bug ID: 5045878 [ja] extra mnemonic characters on control buttons in JFileChooser>http://bugs.sun.com/view_bug.do?bug_id=5045878]] でも、1.6.0は関係なさそう…。 -- [[aterai]] &new{2009-10-09 (金) 20:16:41};
- 6u18で復活:[http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6785462 Bug ID: 6785462 Missing "(O)" in JFileChooser Open button in Windows LAF] -- [[aterai]] &new{2010-06-14 (月) 02:28:39};
- 6u27で、日本語表示の場合などでMnemonicの表示(「開く(O)」の(O)など)が無くなったみたいです: [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7021445 Bug ID: 7021445 Localization needed on resource string for FileChooser Look and Feel code] -- [[aterai]] &new{2011-08-22 (月) 20:23:48};
-- 1.7.0は、「開く(O)」のまま。 -- [[aterai]] &new{2011-08-22 (月) 20:48:03};

#comment