Swing/ApproveButtonText のバックアップの現在との差分(No.3)
TITLE:JFileChooserのボタンテキストを変更
Posted by terai at 2008-10-20
JFileChooserのボタンテキストを変更
JFileChooserのボタンテキストを変更します。- category: swing folder: ApproveButtonText title: JFileChooserのボタンテキストを変更 tags: [JFileChooser, UIManager, Mnemonic] author: aterai pubdate: 2008-10-20T14:22:27+09:00 description: JFileChooserのボタンテキストを変更します。 image:
概要
JFileChooser
のボタンテキストを変更します。
- &jar;
- &zip;
Screenshot
Advertisement
#screenshot
サンプルコード
#spanend
#spandel
UIManager.put("FileChooser.saveButtonText", "保存(S)");
#spanend
#spandel
UIManager.put("FileChooser.openButtonText", "開く(O)");
#spanend
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
#spanadd
// UIManager.put("FileChooser.saveButtonText", "保存(S)");
#spanend
#spanadd
// UIManager.put("FileChooser.openButtonText", "開く(O)");
#spanend
UIManager.put("FileChooser.cancelButtonText", "キャンセル");
JFileChooser fileChooser = new JFileChooser();
#spandel
//fileChooser.setApproveButtonText("開く(O)");
#spanend
#spandel
//fileChooser.setApproveButtonMnemonic('O');
#spanend
#spanadd
// fileChooser.setApproveButtonText("開く(O)");
#spanend
#spanadd
// fileChooser.setApproveButtonMnemonic('O');
#spanend
解説
上記のサンプルは、日本語のWindowsLnFに合わせてJFileChooserのApproveButtonやキャンセルボタンのテキストを以下のように変更しています。解説
上記のサンプルは、日本語のWindowsLookAndFeel
に合わせてJFileChooser
のApproveButton
やキャンセルボタンのテキストを以下のように変更しています。
OpenDialogのデフォルトでは、ファイルリストでフォルダが選択されていると「開く(O)」、ファイルが選択されていると「開く」で切り替わるとボタンサイズが変化してしまうため、「開く(O)」に揃えるSaveDialogのデフォルトでは、ファイルリストでフォルダが選択されていると「開く(O)」、ファイルが選択されていると「保存」なので、「保存(S)」に揃えるCancelButtonのデフォルトは、「取消し」でSaveDialogのフォルダ・ファイルの選択が切り替わるとボタンサイズが変化するので、「キャンセル」に変更
-
OpenDialog
のデフォルトでは、ファイルリストでフォルダが選択された状態の場合「開く(O
)」、ファイルが選択された状態の場合「開く」に切り替わる-
この切り替えでボタンサイズが変化しないように両方「開く(O
)」に揃える
-
-
SaveDialog
のデフォルトではファイルリストでフォルダが選択されていると「開く(O
)」、ファイルが選択されていると「保存」なので「保存(S
)」に揃える-
CancelButton
のデフォルトは「取消し」でSaveDialog
のフォルダ・ファイルの選択が切り替わるとボタンサイズに合わせてレイアウトが変化してしまうので、これを防ぐために二文字分長い「キャンセル」に変更
-
コメント
- 1.6.0_12 以降、デフォルトではMnemonicの表示がなくなっているようです(もしかしてバグだった?)。 -- terai
- メモ: Bug ID: 5045878 [ja] extra mnemonic characters on control buttons in JFileChooser でも、1.6.0は関係なさそう…。 -- terai