JFileChooser - multiple file filters?

bcoughlan picture bcoughlan · Mar 15, 2010 · Viewed 15.7k times · Source

I have a question about the JFileChooser in Swing. I'm trying to get multiple file extensions in the drop-down box, but have no idea how to do it.

There is the method

extFilter = FileNameExtensionFilter(description, extensions);

that I can then use by writing

fileChooser.setFileFilter(extFilter);

however, as you can see, this only supports one option in the drop-down list. How do I add more?

Answer

Amir Afghani picture Amir Afghani · Mar 15, 2010

I think you want the addChoosableFileFilter method. Read the tutorial.

You can simply create a filter that subclasses FileFilter and call the method I outlined above with that filter as an argument.