Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use JFileChooser to select directories only ??  RSS feed

 
Rite Sara
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • 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 ??


 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!