Animated ImageIcon .gif in JLabel
Hi. I have a 4 frame .gif animation of a flashing star. When I load it into an ImageIcon using the ImageIcon constructor;
ImageIcon icon = new ImageIcon("star.gif");
and attach it to a JLabel;
JLabel starLabel = new JLabel(icon);
the animation steps through it's frames so fast that it looks like it must be a graphic glitch. It doesn't matter how many times I slow down the animation using various tools (yes I even made it go 1 frame per 10 seconds in internet explorer but no difference), the animation is still playing at an unacceptable speed.
Am I doing this all wrong?
Thanks for any help.
[641 byte] By [
Maykin53a] at [2007-11-27 1:33:51]

# 3
Animated gif is working fine for me.
You can check the delay time between the images in the gif, to see that it's not too short.
Here's a simple example:import java.net.URL;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import com.sun.imageio.plugins.gif.GIFImageMetadata;
import com.sun.imageio.plugins.gif.GIFImageReader;
public class AnimatedGifTest {
public static void main(String[] args) {
try {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
URL url = new URL("http://www.gifanimations.com/action/SaveImage?path=/Image/Animations/Cartoons/~TS1176984655857/Bart_Simpson_2.gif");
frame.add(new JLabel(new ImageIcon(url)));
frame.pack();
frame.setVisible(true);
// Read the delay time for the first frame in the animated gif
GIFImageReader reader = (GIFImageReader) ImageIO.getImageReadersByFormatName("GIF").next();
ImageInputStream iis = ImageIO.createImageInputStream(url.openStream());
reader.setInput(iis);
GIFImageMetadata md = (GIFImageMetadata) reader.getImageMetadata(0);
System.out.println("Time Delay = " + md.delayTime);
reader.dispose();
iis.close();
} catch (Exception e) {e.printStackTrace();}
}
}
# 4
> This is a bug
> (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=64
> 53582) and the state in "In progress, bug".
How is that a bug? The evaluation clearly states that this happens on zero frame delays, which is handled by the browsers by artificially changing it to 100ms.