afaik, if a user doesn't have a system permission to create a new folder in a given directory, the button will be disabled automatically. If a user can create folders, then disabling the button won't buy you anything excep pissing off those users who won't be able to do what they want and will have to switch back to the system.
> If a user can create
> folders, then disabling the button won't buy you
> anything excep pissing off those users who won't be
> able to do what they want and will have to switch
> back to the system.
That isnt the purpose of this JFileChooser. Im having the user select a file that is going to be edited later in the program. There is no point of the 'New Folder' button being there.
It's not pretty but works:
JFileChooser chooser = new JFileChooser();
disableCtrlBtn(chooser, "Create New Folder");
/*********/
void disableCtrlBtn(Container container, String btnTooltipText){
int cnt = container.getComponentCount();
for (int i=0; i<cnt; i++) {
Component comp = container.getComponent(i);
if (comp instanceof JButton){
JButton btn = (JButton)comp;
if (btn.getToolTipText().indexOf(btnTooltipText)>-1){
btn.setVisible(false);
return;
}
}
else if (comp instanceof JPanel)
disableCtrlBtn((Container) comp, btnTooltipText);
}
}