How do I display an image on a JLabel
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sowjanya_Raghu
Posted On:   Monday, November 5, 2001 05:30 PM

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. Any idea as to where I am going wrong will b   More>>

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.

Any idea as to where I am going wrong will be much appreciated.


Thanks,

   <<Less

Re: How do I display an image on a JLabel

Posted By:   mohammad_afzal  
Posted On:   Wednesday, November 7, 2001 01:55 AM

The simple Syntax to display an image on a JLabel is as Follows:-


JLabel lab=new JLabel(new ImageIcon("pictureName.gif"));
About | Sitemap | Contact