• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use JFileChooser to select directories only ??

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

On browse button I am using following code to select files of type .xls

public JFileChooser _fileChooser = new JFileChooser();

private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {

FileFilter filter1 = new ExtensionFileFilter("xls", new String[] { "XLS" });
_fileChooser.setFileFilter(filter1);
int retval = _fileChooser.showDialog(this,"Select");
if (retval == JFileChooser.APPROVE_OPTION) {
//... The user selected a file, get it, use it.
File file = _fileChooser.getSelectedFile();
path = file.getAbsolutePath();
metadataPath.setText(path);
}
}

but, using this I am able to select only files...

Now I want a code that will be able to select only directories and not files .. Like the functionality of choosing path to store file ... i.e to give destination to store files ... and not to select files ..

Could anyone please give sample code for this ??


 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the JFileChooser API and follow the link to the section in the Swing tutorial on "How to Use File Choosers", where you will find an example.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic