I am trying to add a background image to a JPanel. The paint Component doesn't seem to paint the image imported for the background . Could anyone point out why? I have imported all the necessary libraries.
public class ImagePanel extends JPanel {
public static BufferedImage image;
public ImagePanel() {
try {
image = ImageIO.read(new File("cards/background.png"));
System.out.println("Image Import Succesful");
} catch (IOException ex) {
System.out.println("IMAGE IMPORT ERROR");
}
ImageIcon icon = new ImageIcon(image);
icon.setImage(image);
JLabel imageLabel = new JLabel(icon);
add(imageLabel);
}
@Override
protected void paintComponent(Graphics g) {
System.out.println("painted");
super.paintComponent(g);
g.drawImage(image, 100, 100,
this);
}
}