Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Add Image icon to jpanel

888525Aug 6 2012 — edited Aug 7 2012
I have to add an image to a jpanel.
I am using the below code
I have already defined the jlabel(lblImageIcon) using the netbeans design palette and made the jlabel visibility false.
lblImageicon=new JLabel

lblImageicon.setText("ImageIcon")

gridBagConstraints =new java.awt.GridBagConstraints

gridBagConstraints .gridX=2

gridBagConstraints .gridY=2

add(lblImageIcon,gridBagConstraints )

Then when I have to show the image upon a condition I have the following

ImageIcon icon = new ImageIcon("http://ipaddress/test/test.png)

lblImageIcon.setIcon(icon)

lblImageicon.setVisible(true)

The iamge does not show up.If I do a system.out afetr the line
ImageIcon icon = new ImageIcon("http://ipaddress/test/test.png)
It show as http://ipaddress/test/test.png)

I am not sure whether it is reading the image or not showing the image because of size.Also my application uses applet and I am signing the applet.

Is there any other way to add the images or what am I doing wrong or missing.

Thanks,
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 4 2012
Added on Aug 6 2012
1 comment
428 views