• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Displaying directories only using FileDialog

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

------------------
Hima
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

David
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic