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

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

#screenshot

**サンプルコード [#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の表示がなくなっているようです(もしかしてバグだった?)。 -- [[terai]] &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は関係なさそう…。 -- [[terai]] &new{2009-10-09 (金) 20:16:41};
- 6u18で復活:[[Bug ID: 6785462 Missing "(O)" in JFileChooser Open button in Windows LAF>http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6785462]] -- [[terai]] &new{2010-06-14 (月) 02:28:39};

#comment