Animated GIF question

Hi,

I am trying the change the icon used in a radioButton. I can use the setIcon method to set the GIF image. However, if the GIF image is an animated GIF, nothing is displayed. Are animated GIFs not supported ?

I am using NetBeans 5.0 in a Windows environment.

Thanks in advance,

Steve

[317 byte] By [bronze-starDukes] at [2007-11-26 12:10:48]
# 1

Just as a followup, here is a snippit of the code:

.

.

ImageIcon greenAnimIcon = new ImageIcon(this.getClass().getResource("greenanim.gif"));

.

.

.

emsLed.setIcon(greenAnimIcon);

.

.

.

The icon appears but no animation takes place. Does my Java code need to handle the displaying of an animated GIF differently that if the image just just a single/stationary image?

I am basically using radioButtons to act line LEDs on a front panel of our product. Sometimes a LED will be solid green or red and other times it would be flashing green or red, etc. All works fine if I don't want the LEDs to flash.

The animated GIF works fine if I display it in a browser window. I created it with Paint Shop Pro Animation Shop, so I think the gif file itself is fine.

Thanks in advance,

Steve

bronzestar at 2007-7-7 14:08:19 > top of Java-index,Archived Forums,Socket Programming...
# 2

Try using a simple constructor for the ImageIcon. This works fine for me (tested it with an animated gif).

package testing;

import javax.swing.*;

public class Test

{

public static void main(String[] args)

{

JFrame frame = new JFrame("Test");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.add(new JLabel(new ImageIcon("filename")));

frame.pack();

frame.setVisible(true);

}

}

Cheers

silverstar at 2007-7-7 14:08:19 > top of Java-index,Archived Forums,Socket Programming...
# 3
This is great. I guess you can't use animated GIFs with the Radio Button images. I changed my code to use Labels and all is fine now. It works !Thanks and Best Regards,Steve
bronzestar at 2007-7-7 14:08:19 > top of Java-index,Archived Forums,Socket Programming...
# 4

Now try this with an animated gif. =)

package testing;

import javax.swing.*;

public abstract class Test

{

public static void main(String[] args)

{

JFrame frame = new JFrame("Test");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.add(new JRadioButton(new ImageIcon("filename")));

frame.pack();

frame.setVisible(true);

}

}

Jukka

silverstar at 2007-7-7 14:08:19 > top of Java-index,Archived Forums,Socket Programming...