문제

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?

도움이 되었습니까?

해결책

ImageIO returns BufferedImage

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top