Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFileChooser - multiple file filters?

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?

like image 362
bcoughlan Avatar asked Mar 15 '10 20:03

bcoughlan


2 Answers

use

filter.addChoosableFileFilter(new FileNameExtensionFilter(description, extensions));

as many as the number of your extensions.

like image 128
Younes Meridji Avatar answered Oct 25 '22 13:10

Younes Meridji


I know this question was asked long back, but one can take the following steps to define multiple extensions:

JFileChooser jfc = new JFileChooser(); jfc.setFileFilter(new FileNameExtensionFilter("Select XSL Files","xsl","xslt"));

like image 21
Geebee Avatar answered Oct 25 '22 15:10

Geebee