Java: show GIF image doesn't work

I'm trying to show a GIF image inside a JLabel using the following code

Image waitImage = null;
        JLabel l1;
        try {
            waitImage = ImageIO.read(IndexesPanel.class.getResource("/images/error.gif"));
            l1 = new JLabel(new ImageIcon(waitImage));
            l1.setBounds(20, 20, 100, 100);
            waitPanel.add(l1);

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

The image is shown, but it's not animated. I'm using the following Gif:

Any idea?

Answers


ImageIO returns BufferedImage

Use new ImageIcon(new URL("path to resource"));

Guess you can use new ImageIcon(IndexesPanel.class.getResource("/images/error.gif"));


Need Your Help

How to open Bluetooth Settings from a WPF Application?

c# wpf windows-10-desktop

I am developing a Windows 10 WPF application and I am using 32feet.net for working around with the Bluetooth. Now I am facing a problem to Turn Off/On the Bluetooth programmatically so the alternat...

Generate Map<String,String> from POJO

java android pojo listactivity

I have a POJO, and a (currently not-yet-built) class that will return Lists of it. I'd like to automatically generate the code necessary for the POJO to be accessed as a Map. Is this a good idea, i...