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 - 多个文件过滤器?
基础教程推荐
- 在springboot中如何给mybatis加拦截器 2023-04-29
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- JPA惰性列表上的流 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
