JFileChooser - 多个文件过滤器? [英] JFileChooser - multiple file filters?
本文介绍了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);
我可以通过写作来使用
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.
这篇关于JFileChooser - 多个文件过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文