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
# 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
# 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
# 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