Hi there, i have this code:
openMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int state = chooser.showOpenDialog(frame);
if (state == JFileChooser.APPROVE_OPTION) {
File directory = chooser.getSelectedFile();
imageFiles = directory.listFiles(new ImageListFileFilter());
for (int i = 0; i < imageFiles.length; i++) {
//imageContainers.add(new Thumbnail(fullSize, i));
imageContainers.add(new JButton());
imageContainers.get(i).setIcon(new ImageIcon(new Picture(imageFiles[i], true).getPicture()));
imageContainers.get(i).addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
File x = imageFiles[i];
fullSize.setIcon(new ImageIcon(new Picture(imageFiles[0], false).getPicture()));
}
});
panel.add(imageContainers.get(i));
}
}
}
});
And in the variable 'i' on the line
It gives me this error:
Cannot refer to a non-final variable i inside an inner class defined in a different method
I couldn't find anywhere to solve it on the internet.
Can anyone help me please it's really important.
Thanks in advance.