How to gray out the files in JFileChooser?  
Author Message
RC





PostPosted: 2007-4-25 23:02:00 Top

java-programmer, How to gray out the files in JFileChooser? I only let user select the directories,
not let user select the files.

So I

myFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

That is fine, but user complain about that, they want to
make sure there are files under the directory.

If I do

myFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

Then user will mistake select a file, which I don't let them select a
file. I need to popup a dialog says "Please select a directory only".

The idea thing is I can gray out the file names, so user can see
there are files under a directory, but they can't select any file,
only can select a directory.

Anyone out there has any idea how to gray out the file names in
JFileChooser?

Thank Q!
 






PostPosted: 2007-4-26 2:21:00 Top

java-programmer >> How to gray out the files in JFileChooser? continue to show only directories like you have.
but, use a filter to only show directories that contain files.

there is documentation on this in the java api docs.

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JFileChooser.html