File[] array to imageicon java

344 Views Asked by At

I am using a JFilehooser to load multiple images to a File[].

I then want to load the File[] to multiple ImageIcons. For example:

if (returnValue == JFileChooser.APPROVE_OPTION) {
    File[] files = fileChooser.getSelectedFiles();
    ImageIcon MyImage = new ImageIcon();
    MyImage = files[0];
}

Of course that code doesn't work, but that's what I want to do. How do I do it?

1

There are 1 best solutions below

0
On

As I understand you want to create array of ImageIcon for selected files:

ImageIcon[] imageIcon = Arrays.stream(files).map(file -> new ImageIcon(file.getAbsolutePath())).toArray(ImageIcon[]::new);