Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2006

Tip: Looking for answers? Try searching our database.

fileChooser question

Thread view: 
raphfrk@netscape.net - 24 May 2006 13:45 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.

   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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.