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);
然后我可以通过写作来使用
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.
这篇关于JFileChooser - 多个文件过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JFileChooser - 多个文件过滤器?


- 未找到/usr/local/lib 中的库 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 获取数字的最后一位 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 转换 ldap 日期 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01