获取 FileChooser 的 ExtensionFilters 的所有扩展
Get all Extensions of the ExtensionFilters of a FileChooser
我想在最后添加一个 ExtensionFilter
(支持的文件),将之前过滤器的所有扩展名添加到 FileChooser
。
这是我试过的:
FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().addAll(
new ExtensionFilter("Image Files", "*.png", "*.jpg"),
new ExtensionFilter("Video Files", "*.mp4")), //And so on...
ArrayList<String> supportedExt = new ArrayList<String>();
for(int x = 0; x < chooser.getExtensionFilters().size(); x++) {
// And here I get this:
//The method addAll(Collection<? extends String>) in the type ArrayList<String> is not applicable for the arguments (FileChooser.ExtensionFilter)
supportedExt.addAll(chooser.getExtensionFilters().get(x));
}
chooser.getExtensionFilters().add(new ExtensionFilter("supported Files", supportedExt));
如您所见,我收到此错误:
The method addAll(Collection) in the type ArrayList is not applicable for the arguments (FileChooser.ExtensionFilter)
还有其他方法吗?
编译器告诉你所有你需要知道的。 chooser.getExtensionFilters()
returns FileChooser.ExtensionFilter
列表,但您的 supportedExt
被定义为接受 String
。
您可能打算:
supportedExt.addAll( chooser.getExtensionFilters().get(x).getExtensions() );
您将 supportedExt
声明为 List<String>
是 b/c。
你应该在 class FileChooser.ExtensionFilter
中使用 getExtensions()
我想在最后添加一个 ExtensionFilter
(支持的文件),将之前过滤器的所有扩展名添加到 FileChooser
。
这是我试过的:
FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().addAll(
new ExtensionFilter("Image Files", "*.png", "*.jpg"),
new ExtensionFilter("Video Files", "*.mp4")), //And so on...
ArrayList<String> supportedExt = new ArrayList<String>();
for(int x = 0; x < chooser.getExtensionFilters().size(); x++) {
// And here I get this:
//The method addAll(Collection<? extends String>) in the type ArrayList<String> is not applicable for the arguments (FileChooser.ExtensionFilter)
supportedExt.addAll(chooser.getExtensionFilters().get(x));
}
chooser.getExtensionFilters().add(new ExtensionFilter("supported Files", supportedExt));
如您所见,我收到此错误:
The method addAll(Collection) in the type ArrayList is not applicable for the arguments (FileChooser.ExtensionFilter)
还有其他方法吗?
编译器告诉你所有你需要知道的。 chooser.getExtensionFilters()
returns FileChooser.ExtensionFilter
列表,但您的 supportedExt
被定义为接受 String
。
您可能打算:
supportedExt.addAll( chooser.getExtensionFilters().get(x).getExtensions() );
您将 supportedExt
声明为 List<String>
是 b/c。
你应该在 class FileChooser.ExtensionFilter
getExtensions()