I am putting a JFileChooser in my program, but that only takes images. So I decided to add filters:
Code
import javax.swing.*;
public class fileChooser {
public static void main(String[] args) {
JPanel panel = new JPanel();
final JFileChooser fc = new JFileChooser();
int file = fc.showOpenDialog(panel);
fc.addChoosableFileFilter(new ImageFilter());
fc.setAcceptAllFileFilterUsed(false);
}
}
I got that straight from the Java tutorials. But Eclipse underlines the following as an error:
fc.addChoosableFileFilter(new ImageFilter());
fc.setAcceptAllFileFilterUsed(false);
Any suggestions?
For a list of types supported by that JRE on that OS, use
ImageIO.Types seen – Java 1.6/Windows 7
Note: don’t hard-code that list! It might change from version to version, and OS to OS. E.G.
That list would have many more formats if jai was installed.
Filter as it appears in a chooser