Reputation: 1579
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..
Upvotes: 2
Views: 2922
Reputation: 22292
medoapl brings me the answer.
JFileChooser expects a javax.swing.filechooser.FileFilter
when your imports must state you use a java.io.FileChooser
. The first is a class, and the second an interface. So, replace the second by the first in your import.
Upvotes: 3