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 - 多个文件过滤器?
基础教程推荐
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
