I am putting a JFileChooser in my program, but that only takes images. So I decided to add filters:
import javax.swing.*;
public c
You can use FileFilter class and then use setFileFilter()
class ImageFilter extends FileFilter {
@Override
public boolean accept(File pathname) {
String filename = pathname.getName();
if (pathname.isDirectory()) {
return true;
} else if (filename.endsWith("jpg'") || filename.endsWith("jpeg") || filename.endsWith("png") || filename.endsWith("gif")) {
return true;
} else {
return false;
}
}
Now in your main class:
fc.setFileFilter(new ImageFilter());