Link to home
Start Free TrialLog in
Avatar of aquasw
aquasw

asked on

JFileChooser limit access

Hi experts,
I would like to limit the JFileChooser to save files in a specific directory tree.
I'm able to set the default directory but the user can always brows to deferent place in the file system. I would like to force him to save the file in the file tree under the default directory.
Thanks,
Avatar of Mick Barry
Mick Barry
Flag of Australia image

use a FileFilter that does not accept directories
>>I would like to force him to save the file in the file tree under the default directory.

It would be better for you to question why not doing so would cause you a problem. Say s/he *can't* save it there for any reason. It would be better to adapt your program to deal with it wherever it is
define your own FileSystemView and set it to JFileChooser. In the file system view, return the default dir as the root and disable the navigation.
Avatar of aquasw
aquasw

ASKER

Thanks,
How do I disable the navigation?
did u try what I suggested?
if you don't display directories, then they can't navigate to them :)
Changing the view's not solution, since they can, and probably will, change the *model* by typing in the path into your broken file dialog
Avatar of aquasw

ASKER

objects,
I do want them to navigate directory inside the root directory.
CEHJ,
Is there any why to block the model change?
ASKER CERTIFIED SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can block it by setting the selection mode to files only!
if you need more control over the UI, extend the file chooser UI for your platform!
> I do want them to navigate directory inside the root directory.

then just block access to the any directories that are not descended from the root using the same technique I suggested earlier.