Java FileFilter
Posted
by Mr CooL
on Stack Overflow
See other posts from Stack Overflow
or by Mr CooL
Published on 2010-03-17T09:07:52Z
Indexed on
2010/03/17
9:11 UTC
Read the original article
Hit count: 265
java
|jfilechooser
public class DocFilter extends FileFilter { public boolean accept(File f) { if (f.isDirectory()) { return true; }
String extension = Utils.getExtension(f);
if (extension != null) {
if (extension.equals(Utils.doc) ||
extension.equals(Utils.docx) )
{
return true;
} else {
return false;
}
}
return false;
}
//The description of this filter
public String getDescription() { return "Just Document Files"; }
}
Netbeans compiler warned with the error, "No interface expected here" for above code
Anyone has idea what was the problem?? I tried changing the 'extends' to 'implements', however, it didn't seem to work that way.
and when I changed to implements, the following code cannot work,
chooser.addChoosableFileFilter(new DocFilter());
and with this error,
"method addChoosableFileFilter in class javax.swing.JFileChooser cannot be applied to given types required: javax.swing.filechooser.FileFilter"
Can anyone help on this? Thanks..
© Stack Overflow or respective owner