简体   繁体   English

JavaFX FileChooser选择文件和/或目录?

[英]JavaFX FileChooser select files and/or directories?

JavaFX allows selecting a file via FileChooser and selecting a directory via DirectoryChooser, but how do I allow it to select both at once? JavaFX允许通过FileChooser选择文件并通过DirectoryChooser选择目录,但是如何允许它同时选择两者?

Something like Swing's JFileChooser.FILES_AND_DIRECTORIES option. 类似于Swing的JFileChooser.FILES_AND_DIRECTORIES选项。

Currently I'm just using JFileChooser directly, but it's not exactly a good visual match: 目前我只是直接使用JFileChooser,但它并不是一个很好的视觉匹配:

JFileChooser chooser = new JFileChooser(".");
chooser.setMultiSelectionEnabled(true);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int ret = chooser.showOpenDialog(null);
if(ret == JFileChooser.APPROVE_OPTION) {
    File[] files = chooser.getSelectedFiles();
    ...
}

JavaFX allows selecting a file via FileChooser and selecting a directory via DirectoryChooser, but how do I allow it to select both at once? JavaFX允许通过FileChooser选择文件并通过DirectoryChooser选择目录,但是如何允许它同时选择两者?

There is no such functionality in JavaFX 2.2 or current JavaFX 8 builds. JavaFX 2.2或当前的JavaFX 8版本中没有这样的功能。


A FILES_AND_DIRECTORIES chooser for JavaFX was requested in RT-22621 . RT-22621中请求了用于JavaFX的FILES_AND_DIRECTORIES选择器。

The request was declined as Won't Fix for the following reason: 由于以下原因,请求被拒绝,因为无法修复:

Lubomir Nerad added a comment - Jun, 19 2012 06:59 AM JavaFX uses the corresponding native dialogs for its file and directory chooser. Lubomir Nerad添加了评论 - Jun,19 2012 06:59 AM JavaFX使用相应的本机对话框作为其文件和目录选择器。 Unless the native file dialogs on all supported platforms can provide this feature, we won't be able to add it to the API. 除非所有支持的平台上的本机文件对话框都能提供此功能,否则我们将无法将其添加到API。

Lubomir Nerad added a comment - Jul, 24 2012 06:54 AM The requested functionality is not provided by the platform dialogs on Window XP and Linux/GTK. Lubomir Nerad添加了评论 - 2012年7月24日06:54 AM Window XP和Linux / GTK上的平台对话框未提供所请求的功能。

For Java 8, Windows XP is no longer supported and perhaps Linux will be enhanced to natively provide such functionality so that JavaFX could use it and such a feature could be provided in JavaFX in the future. 对于Java 8,不再支持Windows XP,并且可能会增强Linux以本机提供此类功能,以便JavaFX可以使用它,并且将来可以在JavaFX中提供此类功能。 You may comment on the linked Jira case to register your interest. 您可以评论链接的Jira案例以注册您的兴趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM