title: Loading animated gif from JAR file into ImageIcon
body: <p>I'm trying to create a ImageIcon from a animated gif stored in a jar file.</p>
  
  <pre><code>ImageIcon imageIcon = new ImageIcon(ImageIO.read(MyClass.class.getClassLoader().getResourceAsStream("animated.gif")));
  </code></pre>
  
  <p>The image loads, but only the first frame of the animated gif.  The animation does not play. </p>
  
  <p>If I load the animated gif from a file on the filesystem, everything works as expected.  The animation plays through all the of frames.  So this works:</p>
  
  <pre><code>ImageIcon imageIcon = new ImageIcon("/path/on/filesystem/animated.gif");
  </code></pre>
  
  <p>How can I load an animated gif into an ImageIcon from a jar file?</p>
  
  <p>EDIT:   Here is a complete test case, why doesn't this display the animation?</p>
  
  <pre><code>import javax.imageio.ImageIO;
  import javax.swing.*;
  
  public class AnimationTest extends JFrame {
  
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  AnimationTest test = new AnimationTest();
                  test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  test.setVisible(true);
              }
          });
      }
  
      public AnimationTest() {
          super();
          try {
              JLabel label = new JLabel();
              ImageIcon imageIcon = new ImageIcon(ImageIO.read(AnimationTest.class.getClassLoader().getResourceAsStream("animated.gif")));
              label.setIcon(imageIcon);
              imageIcon.setImageObserver(label);
              add(label);
              pack();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>