hi all.. I would like to create a dialog box that would allow the user to choose a directory, not a file. Is there any way to use the FileDialog box available in AWT to do this (and using Swing is not an option)?? Or do I need to custom write it myself - if so, any ideas or samples to how to do this would be greatly appreciated!
Create a class that implements the java.io.FilenameFilter interface and override the accepts method. Use the string that is passed in to create a File object and return the result of its isDirectory() method. Then when you create your file dialog, use the setFilenameFilter method and pass it your custom object.
Unfortunately, FileDialog can't actually use FileName filters on Windows machines, so they are of rather limited use. (You can user the method setFileNameFilter(), but the filter installed never actually gets used.) From the API:
Filename filters do not function in Sun's reference implementation for Windows 95, 98, or NT 4.0.
Basically Sun has decided they will never be able to provide this functionality on those platforms using the original API for FileDialog, and have instead put made JFileChooser the preferred component for this sort of thing. Unfortunately, if you can't use Swing, you can't use JFileChooser, and I don't know a good solution for this problem.