java JFileChooser - 多个文件过滤器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2450223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JFileChooser - multiple file filters?
提问by bcoughlan
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.
我有一个关于 Swing 中的 JFileChooser 的问题。我正在尝试在下拉框中获取多个文件扩展名,但不知道该怎么做。
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?
但是,如您所见,这仅支持下拉列表中的一个选项。我如何添加更多?
回答by Amir Afghani
回答by clartaq
回答by Younes Meridji
use
利用
filter.addChoosableFileFilter(new FileNameExtensionFilter(description, extensions));
as many as the number of your extensions.
与您的扩展程序的数量一样多。

