How to add an image to a JPanel?

If you are using JPanels, then are probably working with Swing. Try this:

BufferedImage myPicture = ImageIO.read(new File("path-to-file"));
JLabel picLabel = new JLabel(new ImageIcon(myPicture));
add(picLabel);

The image is now a swing component. It becomes subject to layout conditions like any other component.

Leave a Comment