がこのexampleからインスピレーションを受け、アイコン検索に基づいて、強引な方法です:コードはここで、私はすべてのボタンに、このメソッドを使用しようとしましたが、それは動作しません。ここで
public static void main(final String[] args) {
JFileChooser cho = new JFileChooser();
disableButton(cho, "FileChooser.homeFolderIcon");
disableButton(cho, "FileChooser.upFolderIcon");
disableButton(cho, "FileChooser.newFolderIcon");
cho.showOpenDialog(null);
}
public static void disableButton(final Container c, final String iconString) {
int len = c.getComponentCount();
for (int i = 0; i < len; i++) {
Component comp = c.getComponent(i);
if (comp instanceof JButton) {
JButton b = (JButton) comp;
Icon icon = b.getIcon();
if (icon != null
&& icon == UIManager.getIcon(iconString)) {
b.setEnabled(false);
}
} else if (comp instanceof Container) {
disableButton((Container) comp, iconString);
}
}
}
はJFileChooser
ためUIManager
アイコン識別子のリストである:
FileView.directoryIcon
FileView.fileIcon
FileView.computerIcon
FileView.hardDriveIcon
FileView.floppyDriveIcon
FileChooser.newFolderIcon
FileChooser.upFolderIcon
FileChooser.homeFolderIcon
FileChooser.detailsViewIcon
FileChooser.listViewIcon
あなたはいくつのルックアンドフィールをテストしましたか?いくつのプラットフォームがありますか?問題は、この種のソリューションがすぐに崩壊する傾向があることです。 – MadProgrammer
ありがとうございました。あなたのコードを試してみました.1つ上のレベルで家はまだ働いています... –
多分L&F関連です。あなたのactionMapアプローチでは、マップ内の別のキーを印刷しなければなりません。私の場合、1つ上のレベルへのキーは「上に行く」です。残念ながら、ホームボタンに対応するキーはマップに表示されません。 – Berger