Board index » jbuilder » JFrame and image

JFrame and image


2005-10-13 04:04:34 AM
jbuilder11
Hello everyone,
I have a question, how to show an external image (*.jpg) on a jFrame (not applet).
Is there a specific component?
A small example would be helpful!
Thanks,Steve.
 
 

Re:JFrame and image

Simply use a jlabel would be the easiest and most convenient way.
JLabel label= new JLabel();
One of two ways from here:
One, create an ImagIcon and assign it to the JLabel:
public class YourClass extends JFrame{
ImageIcon lblIcon;
private void jbInit() throws Exception {
lblIcon=new ImageIcon(this.getClass().getResource
("youimage.jpg"));
jLabel1.setIcon(lblIcon);
}
Another way:
JLabel imgLabel= new imgLabel();
jLabel1.setText("<html><img
src='"+this.getClass().getResource("yourimage.jpg")+ "'></html>");
"stefman" < XXXX@XXXXX.COM >wrote in message
Quote

Hello everyone,

I have a question, how to show an external image (*.jpg) on a jFrame (not
applet).
Is there a specific component?
A small example would be helpful!

Thanks,Steve.