Replay a non-looping gif image

前端 未结 2 982
南旧
南旧 2021-01-14 18:31

I\'ve got a non-looping gif that I use as ImageIcon for two JLabels, but not at the same time.

My problem is that when I set the second JLabel\'s icon to be the gif,

相关标签:
2条回答
  • 2021-01-14 19:14

    Ok,

    discarded old answer. After some more searching around I found the way to do it.

    ImageIcon icon = ..[the animated gif without looping]..
    ....
    label1.setIcon(icon); //animation plays once
    ....
    // now time to remove icon from label1 and add it to label2
    label1.setIcon(null);
    icon.getImage().flush(); //reset resource used by the image
    label2.setIcon(icon);
    ....
    

    Java Api: Image#flush()

    btw. if you leave the line label1.setIcon(null); out it will still repeat the animation of the icon only for label2. label1 stays at the last frame.

    0 讨论(0)
  • 2021-01-14 19:17

    On the newly created icon try using:

    icon.getImage().flush();
    
    0 讨论(0)
提交回复
热议问题