java JavaFX FileChooser 选择文件和/或目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12644861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaFX FileChooser select files and/or directories?
提问by Mike Emery
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();
...
}
回答by jewelsea
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. Unless the native file dialogs on all supported platforms can provide this feature, we won't be able to add it to the 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 年 6 月 19 日上午 06:59 JavaFX 为其文件和目录选择器使用相应的本机对话框。除非所有支持平台上的本机文件对话框都可以提供此功能,否则我们将无法将其添加到 API 中。
Lubomir Nerad 添加了评论 - 2012 年 7 月 24 日上午 06:54 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. You may comment on the linked Jira case to register your interest.
对于 Java 8,不再支持 Windows XP,也许 Linux 将得到增强以在本机提供此类功能,以便 JavaFX 可以使用它,并且将来可以在 JavaFX 中提供此类功能。您可以对链接的 Jira 案例发表评论以注册您的兴趣。