Home arrow static arrow Java Programming [Archive] - JFileChooser Question
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - JFileChooser Question
This topic has 3 replies on 1 page.

Posts:112
Registered: 10/8/03
JFileChooser Question  
Aug 4, 2004 9:35 AM



 
Hi, I have a question about JFileChooser.

How do I set it so you can only access files in the starting directory?
I tried the option the default option and it did not work...

Also, is there a way to check to see if a folder contains any files?

Thanks,
Ryltar
 

Posts:14,142
Registered: 99-04-02
Re: JFileChooser Question  
Aug 4, 2004 11:08 AM (reply 1 of 3)



 
1) I'm not sure you can. The default directory is just the one to start in. Here's an idea for you to try, if you don't mind reporting it back here...

- Create a class the extends javax.swing.filechooser.FileSystemView
- Let it take a directory which cannot be gone above.
- Override the method: getParentDirectory(File dir) and if the specified directory is the same as the one you can't go above, then return the same directory so going up effectively does nothing.
- Let us know if it works.

2) File.list() will return an empty array if there's nothing in it. You can write a FileFilter that can cause it to look for only files.
 

Posts:112
Registered: 10/8/03
Re: JFileChooser Question  
Aug 5, 2004 6:41 AM (reply 2 of 3)



 
I tried to get that to work, but it didn't work for me... Maybe someone can do it better than I
 

Posts:14,142
Registered: 99-04-02
Re: JFileChooser Question  
Aug 5, 2004 8:32 AM (reply 3 of 3)



 
Yeah, I tried it too... it didn't work either. Well, it might work, if you wrote a wrapper class that takes the real FileSystemView object that the system uses. The problem is that you can't just extend FileSystemView, cuz there is some other concrete implementation of it for each OS. So you'd have to write a FileSystemView subclass that wraps the real one, overriding the get parent method. All other methods would have to invoke the real FSV object... I haven't tried this, but it could work...

IF that doesn't really work, then I don't know what JFileChooser is actually doing with the FSV class (apparently not using it for the directory traversing).
 
This topic has 3 replies on 1 page.