Adding Custom Filter to JFileChooser in Java
JFile chooser doesn't filter any file types. It displays all types of files in the File Chooser dialog. It is the developer responsibility to extend the FileFilter class to filter particular type of file.
See below how to do that:
Extend the FileFilter class as follows.
public class ExampleFileFilter extends FileFilter {
public ExampleFileFilter(String extension, String description) {
this();
if (extension != null) {
addExtension(extension);
}
if (description != null) {
setDescription(description);
}
}
public void setDescription(String description) {
this.description = description;
fullDescription = null;
}
0 comments:
Post a Comment