I am a beginner in java. in a project i want to set an image in a panel. I'm in a fix what to do.
Please anyone help me. Very urgent.
Printable View
I am a beginner in java. in a project i want to set an image in a panel. I'm in a fix what to do.
Please anyone help me. Very urgent.
try this:
1)create an image instance variable:
Image face;
2)load the image in the constructor of the panel:
face= new ImageIcon("image location on disk").getImage();
3) in the paintComponent method after you call super.painComponent(g), call the draw image method and give it as a first parameter face:
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawImage(face,x,y,null) // x,y = position of image, null = imageobserver
}
hope this helps...