Problem with animated gif image getting displayed

My problem is that my animated image does not get displayed properly. I am extending JButton and the button already contains a static image. I want to display the animated image over the static one for some reason. If I replace the animated image with a static gif, then there is no problem.
Here is the code that I am using
Icon anim = new ImageIcon((new ImageLoader()).getImage("/graphics/busy.gif"));
// thread to call displayAnim method
class ColorThread extends Thread {
ColorThread() {
public void run() {
while (AnimFlag) {
try {
displayAnim();
Thread.sleep(400);
} catch (InterruptedException e) {
public void displayAnim()
repaint();
public void paint(Graphics g)
super.paint(g);
int x=5;
int y=0;
if ( AnimFlag) {
anim.paintIcon(this,g,x,y);

This code is working fine for JRE 1.2 and the animation is displayed. The problem is with JRE 1.3. when there is no animation, neither is there any image getting displayed.

Similar Messages

  • Problem with animated .gif

    I have a problem with animated gifs. So if I set a animated gif as background and a button is over it as in the example below, then everytime the animation goes on the button disappears until I go over it with the mouse. So what can I do to solve this?
    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    public class FrameBackImage {
              public static void main(String args []){
                   final JFrame frame = new JFrame("Frame");
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   frame.setSize(400, 400);
                   frame.setResizable(false);
                   frame.setLayout(null);
                   java.net.URL imageURL = ImageApp.class.getResource("animatedw.gif");
                   ImageIcon imageIcon = new ImageIcon(imageURL);
                 final JLabel label = new JLabel(imageIcon);
                 label.setBounds(0,0 , 400, 400);
                 frame.getLayeredPane().add(label);
                 JButton button = new JButton ("Exit");
                 button.setBounds(200, 129, 60, 60);
                 button.setBackground(Color.black);
                 button.setForeground(Color.white);
                 frame.add(button);
                 button.addActionListener(
                 new ActionListener(){
                        public void actionPerformed(ActionEvent arg0) {
                             System.exit(0);
                 frame.validate();
                  frame.setVisible(true);
    }

    In the future, Swing related questions should be posted in the Swing forum.
    Your usage of the getLayeredPane() method is something I've never seen before, so I don't know if thats the problem or not.
    How to display a "background image" is asked all the time in the Swing forum. So to familiarize yourself with the forum you can try searching the Swing forum. Using the keywords I highlighted would be a good place to start.

  • Animated GIF image gets distorted while playing.

    Hi,
    I have some animated gif images which I need to show in a jLabel and a jTextPane. But some of these images are getting distorted while playing in the two components, though these images are playing properly in Internet Explorer. I am using the methods insertIcon() of jTextPane and setIcon() of jLabel to add or set the gif images in the two components. Can you please suggest any suitable idea of how I can get rid of this distortion? Thanks in advance.

    In the code below is a self contained JComponent that paints a series of BufferedImages as an animation. You can pause the animation, and you specify the delay. It also has two static methods for loading all the frames from a File or a URL.
    Feel free to add functionality to it, like the ability to display text or manipulate the animation. You may wan't the class to extend JLabel instead of JComponent. Just explore around with the painting. If you have any questions, then feel free to post.
    The downside to working with an array of BufferedImages, though, is that they consume more memory then a single Toolkit gif image.
    import javax.swing.JComponent;
    import java.awt.image.BufferedImage;
    import java.awt.Graphics;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageReader;
    import javax.imageio.stream.ImageInputStream;
    public class JAnimationLabel extends JComponent {
        /**The default animation delay.  100 milliseconds*/
        public static final int DEFAULT_DELAY = 100;
        private BufferedImage[] images;
        private int currentIndex;
        private int delay;
        private boolean paused;
        private boolean exited;
        private final Object lock = new Object();
        //the maximum image width and height in the image array
        private int maxWidth;
        private int maxHeight;
        public JAnimationLabel(BufferedImage[] animation) {
            if(animation == null)
                throw new NullPointerException("null animation!");
            for(BufferedImage frame : animation)
                if(frame == null)
                    throw new NullPointerException("null frame in animation!");
            images = animation;
            delay = DEFAULT_DELAY;
            paused = false;
            for(BufferedImage frame : animation) {
                maxWidth = Math.max(maxWidth,frame.getWidth());
                maxHeight = Math.max(maxHeight,frame.getHeight());
            setPreferredSize(new java.awt.Dimension(maxWidth,maxHeight));
        //This method is called when a component is connected to a native
        //resource.  It is an indication that we can now start painting.
        public void addNotify() {
            super.addNotify();
            //Make anonymous thread run animation loop.  Alternative
            //would be to make the AnimationLabel class extend Runnable,
            //but this would allow innapropriate use.
            exited = false;
            Thread runner = new Thread(new Runnable() {
                public void run() {
                    runAnimation();
            runner.setDaemon(true);
            runner.start();
        public void removeNotify() {
            exited = true;
            super.removeNotify();
        /**Returns the animation delay in milliseconds.*/
        public int getDelay() {return delay;}
        /**Sets the animation delay between two
         * consecutive frames in milliseconds.*/
        public void setDelay(int delay) {this.delay = delay;}
        /**Returns whether the animation is currently paused.*/
        public boolean isPaused() {
            return exited?true:paused;}
        /**Makes the animation paused or resumes the painting.*/
        public void setPaused(boolean paused) {
            synchronized(lock) {
                this.paused = paused;
                lock.notify();
        private void runAnimation() {
            while(!exited) {
                repaint();
                if(delay > 0) {
                    try{Thread.sleep(delay);}
                    catch(InterruptedException e) {
                        System.err.println("Animation Sleep interupted");
                synchronized(lock) {
                    while(paused) {
                        try{lock.wait();}
                        catch(InterruptedException e) {}
        public void paintComponent(Graphics g) {
            if(g == null) return;
            java.awt.Rectangle bounds = g.getClipBounds();
            //center image on label
            int x = (getWidth()-maxWidth)/2;
            int y = (getHeight()-maxHeight)/2;
            g.drawImage(images[currentIndex], x, y,this);
            if(bounds.x == 0 && bounds.y == 0 &&
               bounds.width == getWidth() && bounds.height == getHeight()) {
                 //increment frame for the next time around if the bounds on
                 //the graphics object represents a full repaint
                 currentIndex = (currentIndex+1)%images.length;
            }else {
                //if partial repaint then we do not need to
                //increment to the the next frame
    }

  • Problem with animated gif when direct image sharing over iChat

    Im having an issue that an animated gif isnt displaying animated when I drag and drop it into an instant message window with a buddy. I drag it from Firefox animated into the chat window but its doesnt get animated. I can see his gifs are animated when he drags and drops it from Safari into the chat window. Does the internet browser make a difference, or is there an option I haven't turned on. I tried searching through the preferences and haven't got a clue to what's stopping my gifs from being animated during direct instant message session.
    Im using the latest iChat 5.0.3(745).

    Hi,
    Welcome to the    Discussions
    If you drag the pic to the Desktop (Download) and then drag to the Browser does it display as Animated then ?
    9:03 PM Sunday; December 12, 2010
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"

  • Quality problem with animated gif through flash

    i got a problem with making animated gif through flash.
    on html/swf publication it looks clear.
    but the weird thing is through gif publication, it wouldn't show. and exporting it as a movie as gif cause visual defect when put up on web.
    it looks better when you open it in a browser.
    this is how it looks for a profile gif in thumbnail mode. blocky and unclear.
    how do you get it to look good both in thumbnail mode and in browser mode. i seen other that have a clear gif in thumbnail mode.  are my setting wrong for flash? or should i just do gif in photshop instead. i heard rumors flash don't do gif very well.

    Change your gif export setting under publish...
              Dimensions         : Match movie
              Playback             : Animated
                                        : Loop continuously
              Options               : Optimize colors
                                        : Smooth
              Transparent         : Opaque
              Dither                 : None
              Palette Type       : Adaptive
              Max colors         : 99999

  • Duration problem with animated gif

    Hi!
    I love the animated gif feature and have used it several times successfully.
    This time, it seems to ignoring my settings for duration. I've set the number as high as 1500/100, but when I preview in browser (Mac Safari or Firefox), the images just whip by. I did slice the animated area and optimize it as an animated gif and export it. When I worked with it again this morning, the first image reflected the 1500/100, but the rest are still racing. I've tried to attach file here.
    Also, I'm wondering if this really should be done in Flash rather than FW. The client wants maybe 5 or 6 images and with the 7 test I have now, I see we're at 216K file size. I don't know flash but if the blog theme we use doesn't have something set up, I assume I'll just outsource the Flash development.
    Thanks,
    Caryn

    Okay...it works for me, but....
    One thing to be careful of is saving vs. exporting. When you create your file, you should save it as a Fireworks .png document. Then, to produce your animated .gif, you should export it. I like using the Image Preview (under the File menu), as I can tweak any of the settings I want. Other people prefer the Export item and optimize their output.
    There are two kinds of .png files. A Fireworks .png has all the layers, vector shapes, Web layer, active filters, and special proprietary information that Fireworks uses. A flattened .png is just a bitmap, whether it has 32, 24, or 8 bits. There's no distinction between these files based on the extension. Another user once suggested using .fw.png for Fireworks documents and .png for exported .pngs and I found that a good suggestion.
    In any case, a good rule to follow is to use save when you want a Fireworks .png and export when you want a Web-ready bitmap of any format.
    So, this is my "but." I took your file and changed the durations of the other frames. I saved it as a Fireworks .png. I then went to File > Image Preview and selected Animated GIF as the format. From the Animation tab, I set the number of loops to 3 and exported. I then saved the .png again to store the loop information.
    Here's the .png (474k):
    Here's the animation (303k):
    Given that the .gif format does't have the colors to reproduce photographs well, I still recommend you look into image rotators. These are scripts that can cycle through a set of images. See this thread:
    http://forums.adobe.com/thread/518231?tstart=1

  • Safari 4: Problems with animated GIF

    Hi,
    since I've updated to Mac OS X 10.6 my Safari 4.0.3 has Problems with some animated GIF.
    Some of these smileys look strange.
    OS: Mac OS X 10.6.1
    Mac: iMac (24-inch Early 2008)

    HI,
    Apparently you aren't alone.
    http://discussions.apple.com/thread.jspa?messageID=10059219&#10059219
    Carolyn

  • Problems with animated gifs in Premiere Pro

    Hi everyone,
    I need some help with my video project - I made some animated gifs that I want to add to the end credits. Importing them etc. works just fine, but in the video, the images always show up with a white background (white "box" around the animted figure), although the gifs definitely have a transparent background to start with. If I import them e.g. as png stills, they are transparent.
    Am I doing something wrong? Or is that a Premiere thing&do I have to re-create the animations inside Premiere?
    I couldn't find anything on this in the forum and I am grateful for any help/suggestions!
    Thanks&have a great weekend!
    Patrick
    I am using Premiere Pro CS 5 on a Mac. The gifs were created in Photoshop.

    Welcome to the forum.
    When Still Images show as black, the first things that I investigate is the pixel x pixel dimensions of the images. With many Stills, even if they are within the allowed pixel x pixel range, one's computer's resources can be used up, and an alternate workflow might be useful - Scale the Images to match the Frame Size of the Sequence, prior to Import, in a program, like Photoshop. This ARTICLE might be helpful.
    The second thought is that the video driver is no longer performing properly, and needs to be updated. What is make/model of your graphics card, and what is the current number/date of your installed video driver?
    Good luck,
    Hunt

  • Transparency problem with animated gif within AJAX overlay

    Hello all,
    I have designed and animated a loading spinner in Photoshop CS3, which needs to sit within an Ajax overlay, with transparency set to 75.
    I tried exporting the spinner as an animated gif with a transparent background (using Save for Web), but it gave the animation a pixelated outside edge. Does anybody know how to remedy this?
    As the Ajax overlay is semi-transparent, I tried exporting the animated gif with a black background and transparency set to 75%. I ticked the transparency box in the export window, but once it is loading in the Ajax it doesn't seem to be transparent (see here: http://www.chrisgartside.co.uk/flash/Screenshot.jpg)
    Any help is very much appreciated.
    Best wishes,
    ruth.

    I forgot to mention that the Ajax pop-up is fired up from a Flash gaming applet.
    Thanks very much in advance.
    ruth.

  • Problems with animated gif with ftp publishing

    Hi
    I have successfully tested a site using mobile me. Ready to go online I uploaded it to an ftp host and the animated gifs are not animating, they appear static. Works fine on mobile me so the data is obviously correct. Anyone know why Im having this problem?

    think ive solved it

  • Has Safari 2.0.3 problems with animated Gifs?

    http://www.webgraphics.at/macnews/photo.gif
    This animation runs under Firefox liquid and under Safari badly.
    Newton 120, iMac Blueberry, MDD, 12 PB G4, 15 PB G4, iMac G5, iPod 15, iPod Shuffle, iPod Nano   Mac OS X (10.4)  

    Same problem.
    Gif isn't shown propper anymore. ( www.iguanaloco.ch for example)
    In earlier Safari version it was no problem.
    But I can not tell when the problem started, nor after wich update.
    At my friends iMac G3 OSX 10.3, everything is OK.
    My computer's are up to date.
    PowerBook G4 667, and the PowerMac G5 dual 1.8, both the same situation to the Gif's.
    Sorry if my language is not so nice :
    Apple, you made ****, please correct it asap. and don't becom windows.
    Thanks.

  • Animated GIFs won't display properly in Mail.app

    I have a weird problem with animated GIFs received as attachments in Mail.app. On my Mac mini, they're only displayed as the first frame within the Mail message window and the animations don't play. But on my iMac G4, the same messages display the animations properly within Mail.app. Both Macs are currently running Mac OS X 10.4.4, but I've observed this problem since 10.4.3. I have the same software installed on both machines. Does anyone have any ideas why this is happening?

      * Test.java
      * Created on January 13, 2007, 6:52 PM
      * To change this template, choose Tools | Template Manager
      * and open the template in the editor.
    package Test;
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
      * @author Calbrenar
    public class Test extends JFrame
        private JList testList;
        private DefaultListModel listModel;
        private JScrollPane serverLogScroller;
        private Container container;
        /** Set up GUI */
        public Test()
           super ("List Test");
           //Get content pane
           container = getContentPane();
           container.setLayout(new FlowLayout());
           listModel = new DefaultListModel();
           listModel.addElement("");
           testList = new JList(listModel);
           testList.setVisibleRowCount(1);
           //testList.setFixedCellHeight(35);
           //testList.setFixedCellWidth(400);
           serverLogScroller = new JScrollPane(testList);
           serverLogScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
           serverLogScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
           container.add( new JScrollPane( testList));
           setSize(700, 75);
           setVisible(true);
        public void addStatus(String str)
           listModel.add(0, str);
           //testList.setPreferredSize(new Dimension(400, 15));
           //serverLogScroller.revalidate();
           container.validate();
        public static void main ( String args[])
           Test application = new Test();
           application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
           application.addStatus("-ERR");
           application.addStatus("+OK Enter Password");
           application.addStatus("-ERR Bad Pass");
    } // end class Test

  • Help with animated gif background once opened in Photoshop c33 extended

    I often work with animated Gif's and a
    adding doggies etc to the top layer.
    I am having a problem with animated Gif with (existing transparent) background when saving from the web and opening in Photoshop cs3 extended it is changing the background to White automatically ?  ( which is not what I want)  I would like to know how to keep in the same format with the tranparent or even change to black as that is the background on my website.....do not know why it is converting it to white in photoshop or how to change....Thank you advance!

    Thank you so much....after many hours playing with ....went right too and worked perfect!!  Thank  you !!

  • Problem at displaying animated gif images !!!!!!!!!!!!

    hello everyone......i am trying to display an animated gif image..............so till far i have no issues on this....
    but i face problem when :
    i have created a class called SimpleGame which extends JPanel....
    public class SimpleGame extends JPanel
    //code
    public void paintComponent(Graphics g)
    //code to draw image
    }now i have written another class with main method
    public class MyGame extends SimpleGame
    public MyGame()
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);
            frame.setUndecorated(true);
            frame.setLocationRelativeTo(null);
            frame.getContentPane().add(this);
            frame.setVisible(true);
            this.repaint();
    }so image gets displayed but only one frame of animated image......image that is displayed is static.....since it is a animated gif,,,,,so some how animation is not rendered......only one frame is displayed......
    why is it happening ??
    if i try to display animated image from a single class i mean my paintComponent method and main method is at same class then i do not face problem.....
    but if my paint method is in another class and i am using that method from another class then animation does not get rendered.........
    any help !!!!! please...........

    class SimpleGame extends JPanel
    Image img=new ImageIcon("y.gif");
    public void paintComponent(Graphics g)
    g.drawImage(img,150,150,this);
    }main class//
    class MyGame extends SimpleGame
    public MyGame()
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);
            frame.setUndecorated(true);
            frame.setLocationRelativeTo(null);
            frame.getContentPane().add(this);
            frame.setVisible(true);
            this.repaint();
    public static void main(String[] args)
    new MyGame();
    }my image gets displayed.......but only single frame of a animated image....animation is not happening..........

  • Problems playing animated gif on label again

    I have program that is displaying a graphic representation of a wave file this is a cut down of it. I am using a mouse listener to detect the mouse wheel and from that I am zooming in on the wave graphic or zooming out.
    The problem is when I zoom in a Jlabel is displayed with an animated gif saying �zooming in� that work fine. But as soon as I zoom in again, the Jlabel will not display the image again or the zooming out image.
    I an new to java so be kind to my code
    Any help would be greatly appreciated
    CODE
    * DisWav1.java
    * Created on 30 April 2006, 14:43
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Line2D;
    import java.util.Vector;
    import javax.swing.JPanel;
    import javax.swing.JDialog;
    public class DisWav1 extends JDialog implements Runnable{
    // varables
         private Thread thread;
         public static final int MAX_PRIORITY = 10;
         Vector lines = new Vector();
         Color jfcBlue = new Color(204, 204, 255);
    Color pink = new Color(255, 175, 175);
    private Font font12 = new Font("serif", Font.PLAIN, 12);
    long mainSize = 36000;
    int holdingArray[];
    int ZOOMFactor;
         private JPanel jContentPane = null;
         * This is the default constructor
         public DisWav1() {
              super();
              initialize();
         * This method initializes this
         * @return void
         private void initialize() {
              this.setBackground(java.awt.Color.black);
              this.setContentPane(getJContentPane());
              this.setTitle("Display Wave");
    this.setSize(150,150);
    addMouseWheelListener(new java.awt.event.MouseWheelListener() {
    public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
    formMouseWheelMoved(evt);
         * This method initializes jContentPane
         * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setBackground(java.awt.Color.black);
                   jContentPane.setLayout(new BorderLayout());
              return jContentPane;
         public void run()
    }// end run
    public void start() {
    thread = new Thread(this);
    thread.setName("Display Graph");
    thread.setPriority(MAX_PRIORITY );
    thread.start();
    }// end start
    public void stop() {
    if (thread != null) {
    thread.interrupt();
    thread = null;
    }// end stop
    // Create a array for drawing ines on screen in scale.
    public void moveMe(int x, int y){
    this.setLocation(x,y);
    // used to detect when the mouse is wheel is move and then
    // zoom IN or OUT
    // also display jLabel with animated gif saying "zooming in" or "Zooming out"
    private void formMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
    javax.swing.JLabel zz;
    zz = new javax.swing.JLabel();
    zz.setBounds(this.getWidth()/2, this.getHeight()/2, 140,40);
    zz.setText("");
    getContentPane().add(zz);
    int notches = evt.getWheelRotation();
    if (notches < 0) {
    getContentPane().add(zz);
    zz.setIcon(new javax.swing.ImageIcon("zoomingin.gif"));
    zz.setBounds(this.getWidth()/2-(zz.getWidth()/2), this.getHeight()/2-(zz.getHeight()/2), 140,40);
    System.out.println("zoom up " + ZOOMFactor);
    ZOOMFactor = ZOOMFactor +2;
    } else {
    if (ZOOMFactor <= 0 )
         ZOOMFactor = 1;
    else{
    getContentPane().add(zz);
    zz.setIcon(new javax.swing.ImageIcon("C:zoomingOUT.gif"));
    zz.setBounds(this.getWidth()/2-(zz.getWidth()/2), this.getHeight()/2-(zz.getHeight()/2), 140,40);
    ZOOMFactor = ZOOMFactor - 2;
    System.out.println("zoom down " + ZOOMFactor);
    public void paint(Graphics g) {
    // paints lines form a vector here on the screen
    }// end of paint method
    }// end class disWav1
    // END CODE

    think ive solved it

Maybe you are looking for

  • Difference between booked items and requested items

    Hi Gurus, I wanted to understand the difference between Booking History - booked items – booked date Booking History – requested items –booked date The Series definition has the same definition given in the hint. I checked one of the below links for

  • Using external display as main display-how?

    My subject line says it all. I want to use an external LCD display as my main display while keeping my MacBook Pro closed w/o powering down to sleep. I know this can be done because I've seen posts where other users do it, but I've never learned how

  • Why would my Acrobat tab keep disappearing from my Office programs?

    Every so often, my Acrobat tab keeps disappearing from my Office programs.  It seems totally random, but happens when I am actually using the tool to convert a word doc or excel spreadsheet to PDF.  I am using Office 2007 Professional and Adobe Acrob

  • Java develoment in unix or windows

    Sometimes people ask u 'have u done java development in unix or wondows'. Whats the difference between developing java apps in unix or windows

  • Profit Centerwise Receivable & Payable

    Dear all, Can you help me in getting the open line items as of a given date profitcenterwise (back end table would be faglflexa instead of BSEG) which is similar to our standard T-Code of FBL5N/FBL1N. FBL5N/FBL1N does not give the output on the basis