You want to use them and add a filter. For example:
JFileChooser chooser = new JFileChooser();
ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension("jpg");
filter.setDescription("JPG & GIF Images");
chooser.setFileFilter(filter);
int returnVal = chooser.showSaveDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}
Only JPG and GIF files will be displayed here. Example stolen from here
: , ExampleFileFilter abstact FileFilter
: , , Runtime.getRuntime.exec( ", .doc" ), .
, , JFileChooser. - , , :
JFileChooser chooser = new JFileChooser();
String selectedFile = "The suggested save name.";
chooser.setSelectedFile(selectedFile);
ExampleFileFilter filter = new ExampleFileFilter();
String extension = "Do something to find your extension";
filter.addExtension(extension);
filter.setDescription("JPG & GIF Images");
chooser.setFileFilter(filter);
int returnVal = chooser.showSaveDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}
, .