JavaFX FileChooser选择文件和/或目录? [英] JavaFX FileChooser select files and/or directories?

查看:1893
本文介绍了JavaFX FileChooser选择文件和/或目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaFX允许通过FileChooser选择文件并通过DirectoryChooser选择目录,但是如何允许它同时选择两者?

JavaFX allows selecting a file via FileChooser and selecting a directory via DirectoryChooser, but how do I allow it to select both at once?

类似于Swing的JFileChooser.FILES_AND_DIRECTORIES选项。

Something like Swing's JFileChooser.FILES_AND_DIRECTORIES option.

目前我只是直接使用JFileChooser,但它不是完全是一个很好的视觉匹配:

Currently I'm just using JFileChooser directly, but it's not exactly a good visual match:

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允许通过FileChooser选择文件并通过DirectoryChooser选择目录,但是如何允许它同时选择两个目录?

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 2.2或当前的JavaFX 8版本中没有这样的功能。

There is no such functionality in JavaFX 2.2 or current JavaFX 8 builds.

一个FILES_AND_DIRECTORIES选择器在 RT-22621 中请求了JavaFX。

A FILES_AND_DIRECTORIES chooser for JavaFX was requested in RT-22621.

由于以下原因,请求被拒绝,因为无法修复:

The request was declined as Won't Fix for the following reason:


Lubomir Nerad添加了评论 - Jun ,19 2012 06:59 AM
JavaFX使用相应的本机对话框作为其文件和目录选择器。除非所有支持的平台上的本机文件对话框都能提供此功能,否则我们将无法将其添加到API中。

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添加了评论 - Jul, 24 2012 06:54 AM
Window XP和Linux / GTK上的平台对话框不提供所请求的功能。

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.

对于Java 8,不再支持Windows XP,并且可能会增强Linux以便本机提供此类功能,以便JavaFX可以使用它,并且将来可以在JavaFX中提供此类功能。您可以对链接的Jira案例发表评论以注册您的兴趣。

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.

这篇关于JavaFX FileChooser选择文件和/或目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆