import javax.swing.JPanel; import java.awt.Graphics; import java.awt.Image; public class ImagePanel extends JPanel { private Image img; public ImagePanel(Image img) { super(); this.img = img; } @Override protected void paintComponent(Graphics g) { Graphics newG = g.create(); if (this.isOpaque()) { newG.setColor(this.getBackground()); newG.fillRect(0, 0, this.getWidth(), this.getHeight()); } newG.drawImage(img, 0, 0, img.getWidth(this), img.getHeight(this), this); } }