0

I want to add an ExtensionFilter (supported Files) in the end with all the extensions of the previous filters to a FileChooser.

This is what I've tried:

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));

As you can see, I get this error:

The method addAll(Collection) in the type ArrayList is not applicable for the arguments (FileChooser.ExtensionFilter)

Is there another way of doing it?

James_D
  • 201,275
  • 16
  • 291
  • 322

2 Answers2

0

The compiler is telling you all you need to know. chooser.getExtensionFilters() returns list of FileChooser.ExtensionFilter but your supportedExt is defined to accept String.

You probably intended:

supportedExt.addAll( chooser.getExtensionFilters().get(x).getExtensions() );

tsolakp
  • 5,858
  • 1
  • 22
  • 28
0

It's b/c you declared supportedExt as List<String>. You should use getExtensions() in class FileChooser.ExtensionFilter

zlakad
  • 1,314
  • 1
  • 9
  • 16