JFileChooser - multiple file filters?

2019-04-06 03:08发布

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?

2条回答
Emotional °昔
2楼-- · 2019-04-06 03:38

I'm sure you have already solved this to your satisfaction, but I came across this link at the same time I came across your question. In particular, look at section 3 for a way to generate multiple filters easily.

查看更多
Luminary・发光体
3楼-- · 2019-04-06 03:55

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.

查看更多
登录 后发表回答