JFileChooser - 多个文件过滤器?
我对 Swing 中的 JFileChooser 有疑问.我正在尝试在下拉框中获取多个文件扩展名,但不知道该怎么做.
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.
有方法
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?
推荐答案
我想你想要 addChoosableFileFilter
方法.阅读教程.
I think you want the addChoosableFileFilter
method. Read the tutorial.
您可以简单地创建一个子类 FileFilter
的过滤器,并使用该过滤器作为参数调用我上面概述的方法.
You can simply create a filter that subclasses FileFilter
and call the method I outlined above with that filter as an argument.
相关文章