Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display animated gif on jPanel

Tags:

java

In the overridden function for my JFrame:

@Override
protected void paintComponent(Graphics g) {

    BufferedImage imagePerson;
    try {
        imagePerson = ImageIO.read(new File("errol.gif"));
    } catch (IOException e) {
        imagePerson = null;
    }

    g.drawImage(imagePerson, i * increment, j * increment - 1, null);
}

How can I change this so the animation on the gif is shown (without using threading). I have spent many hours trying to get this to work but to no avail.

like image 727
Yawn Avatar asked Dec 02 '10 19:12

Yawn


1 Answers

You could use an ImageIcon for this purpose. Have a look here and here. If you need the animation on a JPanel, simply add a JLabel (with the ImageIcon) to the panel.

like image 72
aioobe Avatar answered Sep 25 '22 18:09

aioobe