posted 22 years ago
I am having trouble trying to display an image on a JLabel.
The code I have been trying is as follows:
ImageIcon icon = new ImageIcon ("airplane4.gif");
System.out.println("Size of the Image = " +
icon.getIconHeight() + "..." +
icon.getIconWidth());
if (icon == null) {
System.out.println("Icon not loaded");
} else {
System.out.println("Icon loaded = " + icon);
}
JLabel imageLabel = new JLabel(icon);
When I try to display the loaded images's width and height, I get -1 as the reply + The image is also not displayed.
Any idea as to where I am going wrong will be much appreciated.
Thanks,