Java:显示GIF图像不起作用

MaT*_*TTP 0 java swing jlabel animated-gif

我正在尝试使用以下代码在JLabel中显示GIF图像

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();
        }
Run Code Online (Sandbox Code Playgroud)

显示图像,但不是动画.我正在使用以下Gif:

在此输入图像描述

任何的想法?

Sta*_*avL 8

ImageIO 回报 BufferedImage

使用 new ImageIcon(new URL("path to resource"));

猜猜你可以用new ImageIcon(IndexesPanel.class.getResource("/images/error.gif"));