Loading animated GIF in JLabel weirdness

前端 未结 3 671
清歌不尽
清歌不尽 2021-01-13 00:13

I\'m trying to load an animated GIF in a JLabel.

While this works:

URL urlsd;
try {
    urlsd = new URL(\"http://pscode.org/media/starzoom-thumb.gif\         


        
相关标签:
3条回答
  • 2021-01-13 00:54

    So there is also a simpler way of doing it. The following line is how I did it.

    this.setContentPane(new JLabel(new ImageIcon("Path To Gif File")));
    
    0 讨论(0)
  • 2021-01-13 00:55

    You can try loading your GIF file like that:

    public class Test extends JPanel {
        public Test() {
            ImageIcon imageIcon =
              new ImageIcon(Test.this.getClass().getResource("starzoom-thumb.gif"));
        }
    }
    

    Or using Test.class.getResouce() if your context is static.

    0 讨论(0)
  • 2021-01-13 00:56

    Below code worked for me, it will show the animation instead of first frame of the image.

    public class Test extends JPanel {
        public Test() {
            ImageIcon yyyyIcon = new ImageIcon(xxx.class.getClassLoader().getResource("yyyy.gif"));
            connectionLabel.setIcon(yyyy);   
        }
    }
    
    0 讨论(0)
提交回复
热议问题