禁用文件选择器中的新文件夹按钮无法正常工作
我使用以下代码禁用新的“文件夹”按钮:
public void disableNewFolderButton( Container c ) {
System.out.print("in disable fn");
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("FileChooser.newFolderIcon"))
{
System.out.print("in disable fn");
b.setEnabled(false);
}
}
else if (comp instanceof Container) {
disableNewFolderButton((Container)comp);
}
}
}
代码在以下行中调用:
JFileChooser of=new JFileChooser();
of.setAcceptAllFileFilterUsed(false);
of.addChoosableFileFilter(new MyFilter());
disableNewFolderButton(of);
但是,仅在首次显示文件选择器时才会禁用新文件夹按钮。假设我去了一些驱动器,比如说g :,那么按钮再次启用。如何设置这个权利?
没有找到相关结果
已邀请:
3 个回复
逆捐凶撤小
硕歌沙
陈獭