Tuesday, April 2, 2013

Java Swing - how to add an image to a JPanel?

10:11 AM

How to add image inside jPanel ?


import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class ImagePanel extends JPanel{

private BufferedImage image;

public ImagePanel() {
try {
image = ImageIO.read(new File("image name and path"));
} catch (IOException ex) {
// handle exception...
}
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters
}

}



--------------------------------------------------
How to add image inside jPanel ?
Java Swing - how to add image in north of Jpanel
java - how to put Image on JPanel using Netbeans
background image on JPanel Swing
Add an image to JFrame
Adding multiple images to JPanel
Adding picture to Jframe on click‎
Add image to jframe‎
JPanel background picture?‎
How do i add images to java Jframe?
How to set a background image for a JFrame using Jlabel

Written by

We are one of the initiators of the development of information technology in understanding the need for a solution that is familiar and close to us.

0 comments:

Post a Comment

 

© 2013 Klick Dev. All rights resevered.

Back To Top