import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public class ImageGrid {
private JPanel getContent(BufferedImage image) {
JPanel panel = new JPanel(new GridLayout(0,3));
ImageIcon icon = new ImageIcon(image);
for(int j = 0; j < 9; j++) {
panel.add(new JLabel(icon));
}
return panel;
}
public static void main(String[] args) throws IOException {
// image is in the images folder which is in the
// current directory
String path = "images/Rabbit.gif";
BufferedImage image = ImageIO.read(new File(path));
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new ImageGrid().getContent(image));
f.pack();
f.setLocation(200,200);
f.setVisible(true);
}
}
> I don't know why
Neither do we, since we are not mind readers and you demo code is not posted.
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.