I was wondering if there was a way to setup the file chooser so that
directories can be selected but also so that navigation was impossible.
I was the user to pick a sub directory of a given directory. However,
if I enable directories, then the user can change the directory.
fileChooser.setFileSelectionMode(fileChooser.DIRECTORIES_ONLY);
fileChooser.setDialogTitle("Select Directory");
fileChooser.resetChoosableFileFilters();
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setFileFilter(filter);
fileChooser.setCurrentDirectory( rootDir );
filter is a filter that just returns true for directories.
Thomas Weidenfeller - 24 May 2006 14:10 GMT
> I was wondering if there was a way to setup the file chooser so that
> directories can be selected but also so that navigation was impossible.
>
> I was the user to pick a sub directory of a given directory. However,
> if I enable directories, then the user can change the directory.
I haven't done this, but I would start by implementing an own FileView,
where isTraversable() returns false for the particular directories, and
all other methods return null (which delegates the JFileChooser to the
default FileView). Then I would set the new FileView as the FileView for
the JFileChooser.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
Thomas Hawtin - 24 May 2006 14:22 GMT
> I was wondering if there was a way to setup the file chooser so that
> directories can be selected but also so that navigation was impossible.
[quoted text clipped - 8 lines]
> fileChooser.setFileFilter(filter);
> fileChooser.setCurrentDirectory( rootDir );
I guess you could provide a FileSystemView that always returns false for
isTraversable. Or a FileView that returns Files that always claim to be
not directories (that might mess up the icon, for instance).
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/