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,
Java

Avatar of undefined
Last Comment
Mick Barry

8/22/2022 - Mon
Mick Barry

use a FileFilter that does not accept directories
Mick Barry

or better still set file selection mofde to only accept files


http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JFileChooser.html#setFileSelectionMode(int)
CEHJ

>>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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ksivananth

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.
aquasw

ASKER
Thanks,
How do I disable the navigation?
Mick Barry

did u try what I suggested?
if you don't display directories, then they can't navigate to them :)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
CEHJ

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
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
ksivananth

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ksivananth

you can block it by setting the selection mode to files only!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ksivananth

if you need more control over the UI, extend the file chooser UI for your platform!
Mick Barry

> 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.