I am using this code for displaying images on JPanel, in which i succeeded, but the images are volatile. When i maximize or minimize the frame, it vanishes.

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...

    public void paintComponent(Graphics g) {
        g.drawImage(image, 0, 0, this);



Edited by peter_budo: Not snipped, changing to thread

7 Years
Discussion Span
Last Post by tsfaridi

This belongs in a normal thread, not in a code snippet. And I've experienced the same problem in the past, but I did a lot more debugging than you did. For example, when the window is resized, is your paintComponent method called?


Thanks! you have shown me a path, i will work on it. Here the issue arises is, i am working on Checkers game, calling the paint method again will not resolve my issue. As the position of pieces will not be the same as initial.
@BestJewSinceJC: Kindly share with me your experience, how did you resolved this problem ??

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.