0

Hi I am unsure on how to format my animated gif images to let them show on Jars created on eclipse.

try {
        //ImageIcon titleIcon = new ImageIcon(ImageIO.read(getClass().getResource("title.gif")));
        title = new ImagePicture (new ImageIcon(ImageIO.read(getClass().getResource("title.gif"))), 0, 0);
        //title = new ImagePicture (new ImageIcon("title.gif"), 0, 0);

    }//end try 
    catch (IOException e) {

    }//end catch

    //set title bounds
    title.setBounds(260, 0, 400, 100);

That is my code right now for an animated GIF, Thank you for your input.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
Jessica P
  • 1
  • 3
  • 1
    The search term you're looking for is "animated gif in Swing". Eclipse (your IDE) & jars (your runtime) aren't relevant here. – Manius Jan 22 '18 at 21:07
  • `ImageIO` doesn't support animated Gifs, at least not in any reasonable way which can't be achieved with simply using `ImageIcon` directly. Instead, pass the `URL` from `getResource` to `ImageIcon` directly – MadProgrammer Jan 22 '18 at 21:42
  • [As an example of using `ImageIO` vs `ImageIcon`](https://stackoverflow.com/questions/22188940/gif-image-doesnt-moves-on-adding-it-to-the-jtabbed-pane/22190844#22190844) – MadProgrammer Jan 22 '18 at 21:50

1 Answers1

0

Hard to give a good example without more context, but you can try adding the ImageIcon to a JLabel like this.

URL url = this.getClass().getResource("title.gif");
Icon title = new ImageIcon(url);
JLabel titleLbl = new JLabel(title);
//You have to add titleLbl to a container after this, of course
Manius
  • 3,594
  • 3
  • 34
  • 44