I am creating a simple application for test purposes that displays a couple of JFrames separately, and each one contains an image.
The problem is that it displays the number JFrames expected based on the count of images on the list, however, only the last one presents the image. All the other ones are empty.
I've already made a debug, and check that the Buffered Image
list is exactly as expected, all objects are there, and they are copies of each other as it is a test.
Is there anything wrong with the repaint
call (already tried in a variety of places) or with the ImgPanel
subclass? That's my only guess of what could be wrong.
public class Main() extends JFrame{
BufferedImage I;
public void show(ArrayList<BufferedImage> images){
int i = 0;
for(BufferedImage b : images){
this.I = b;
Container c = getContentPane();
c.setLayout(null);
c.add(new ImgPanel());
JFrame frame = new JFrame();
frame.validate();
frame.repaint();
frame.setTitle("Execution: "+i);
frame.getContentPane().add(c);
frame.setSize(800,600);
frame.setVisible(true);
i++;
}
}
public class ImgPanel extends JPanel {
public imgPanel() {
setBounds(0, 0, 800,600);
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(I, 0, 0, this);
}
}
public static void main(String[] args){
//"d" is an Object Already declared
ArrayList<BufferedImage> images = d.getImages();
Main m = new Main();
m.show(images);
}
}