-2

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?

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • You have a problem to load the ImageIcon or to load ImageIcon**s** ? One can be answered [here](https://docs.oracle.com/javase/tutorial/uiswing/components/icon.html). The other can be answered with a loop – AxelH Jan 03 '17 at 10:12

1 Answers1

1

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);
Maxim
  • 9,701
  • 5
  • 60
  • 108