JFileChooser - 多个文件过滤器?
我对 Swing 中的 JFileChooser 有疑问。我试图在下拉框中获取多个文件扩展名,但不知道该怎么做。
方法
extFilter = FileNameExtensionFilter(description, extensions);
然后我可以通过编写使用一种
fileChooser.setFileFilter(extFilter);
,但是,如您所见,这仅支持下拉列表中的一个选项。我如何添加更多?
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.
There is the method
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您需要
addChoosableFileFilter
方法。阅读教程。您可以简单地创建一个过滤器,该过滤器是
FileFilter
的子类,并使用该过滤器作为参数来调用我上面概述的方法。I think you want the
addChoosableFileFilter
method. Read the tutorial.You can simply create a filter that subclasses
FileFilter
and call the method I outlined above with that filter as an argument.我确信您已经解决了这个问题,令您满意,但我遇到了这个 链接 同时我遇到了你的问题。特别是,请参阅第 3 节,了解轻松生成多个过滤器的方法。
I'm sure you have already solved this to your satisfaction, but I came across this link at the same time I came across your question. In particular, look at section 3 for a way to generate multiple filters easily.
使用
与您的分机数量一样多的数量。
use
as many as the number of your extensions.
我知道这个问题很早以前就被问过,但是可以采取以下步骤来定义多个扩展:
JFileChooser jfc = new JFileChooser(); jfc.setFileFilter(new FileNameExtensionFilter("选择 XSL 文件","xsl","xslt"));
I know this question was asked long back, but one can take the following steps to define multiple extensions:
JFileChooser jfc = new JFileChooser(); jfc.setFileFilter(new FileNameExtensionFilter("Select XSL Files","xsl","xslt"));