Pregunta

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:

enter image description here

Any idea?

¿Fue útil?

Solución

ImageIO returns BufferedImage

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

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top