Add Image icon to jpanel
888525Aug 6 2012 — edited Aug 7 2012I 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,