Animated gifs on jlabel

hi
i am new to java and got a question.
how do i place a animated gif on a jlabel correct?
i done it so far with 'seticon' and the gif is visible, but not animated.
what do i have to do?

Use setImageObserver()
ImageIcon myicon = new ImageIcon (...);
JLabel mylabel = new JLabel (myicon);
myicon.setImageObserver (mylabel);
Okay, thank you very much.
Now, the Image is animated after i maximize and reset my application.

Similar Messages

  • Refreshing animated gif in Jlabel

    Hi,
    I've created a GUI for a cashmachine application and have the problem that my animated GIF's work on the first call, but only display the last frame of the animation on subsequent calls.
    I've tried alot of things, including validate, repaint, refresh but im running out of ideas!
    I have come to this assumption because I have created a copy of the animation and imported that on the second call and it works like it should. However once again on subsequent calls it simply displays the last from and doesn't animate.
    The code looks like this:
    public JLabel getInsertCardGraphic() {
              /* Imports the enter card gif */
              ImageIcon enterCardGraphic= new ImageIcon(LOCATION+"moving-card2.gif");
              JLabel enterCardHolder = new JLabel(enterCardGraphic);
              return enterCardHolder;
         }which is called from:
    public void actionPerformed(ActionEvent evt) {
              playBeep();          //not related to problem     
              eastPane.removeAll();
              eastPane.add(getInsertCardGraphic(), BorderLayout.CENTER); //called here
              eastPane.add(getCashSlotImage(), BorderLayout.SOUTH);
              eastPane.validate();
              String cardNum = cardlist.getSelectedItem().toString(); //unrelated code
              char[] pinArray = new char[4];
              pinArray[0] = cardNum.charAt(12);
                    pinArray[1] = cardNum.charAt(8);
                    pinArray[2] = cardNum.charAt(4);
                    pinArray[3] = cardNum.charAt(0);
              String encryptedPIN = new String(pinArray);
              // Tell controller that a card has been entered.
              Controller.getInstance("Ipl/ATM/Model/Model").cardEntered( cardlist.getSelectedItem().toString(), encryptedPIN);
         }if anyone has any suggestions on what I should do I will be extremely greatful!!
    Cheers,
    Hakan
    Edited by: hakz on Nov 13, 2007 5:01 AM

    Animated gif is working fine for me.
    You can check the delay time between the images in the gif, to see that it's not too short.
    Here's a simple example:import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.imageio.stream.ImageInputStream;
    import javax.swing.ImageIcon;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import com.sun.imageio.plugins.gif.GIFImageMetadata;
    import com.sun.imageio.plugins.gif.GIFImageReader;
    public class AnimatedGifTest {
        public static void main(String[] args) {
            try {
                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
                URL url = new URL("http://www.gifanimations.com/action/SaveImage?path=/Image/Animations/Cartoons/~TS1176984655857/Bart_Simpson_2.gif");
                frame.add(new JLabel(new ImageIcon(url)));
                frame.pack();
                frame.setVisible(true);
                // Read the delay time for the first frame in the animated gif
                GIFImageReader reader = (GIFImageReader) ImageIO.getImageReadersByFormatName("GIF").next();
                ImageInputStream iis = ImageIO.createImageInputStream(url.openStream());
                reader.setInput(iis);
                GIFImageMetadata md = (GIFImageMetadata) reader.getImageMetadata(0);           
                System.out.println("Time Delay = " + md.delayTime);
                reader.dispose();
                iis.close();
            } catch (Exception e) {e.printStackTrace();}
    }

  • How can I place my animated gif with JLabel?

    Hello, everyone:
    I've got some problems with displaying animated picture when I
    use ImageIcon class in the JLabel. The picture played very fast than the normal speed. Does anybody have this problem?
    I need your help, thank. If I type some impolite grammer, please forgive me. My English is poor. Thanks

    I Know what problem it is.
    Someone tell me that my animated picture does'nt set the frame delay.
    And I use this site's source code to change my frame delay.
    http://www.fmsware.com/stuff/gif.html

  • Resized animated gif ImageIcon not working properly with JButton etc.

    The problem is that when I resize an ImageIcon representing an animated gif and place it on a Jbutton, JToggelButton or JLabel, in some cases the image does not show or does not animate. More precicely, depending on the specific image file, the image shows always, most of the time or sometimes. Images which are susceptible to not showing often do not animate when showing. Moving over or clicking with the mouse on the AbstractButton instance while the frame is supposed to updated causes the image to disappear (even when viewing the non-animating image that sometimes appears). No errors are thrown.
    Here some example code: (compiled with Java 6.0 compliance)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test
         public static void main(String[] args)
              new Test();
         static final int  IMAGES        = 3;
         JButton[]           buttons       = new JButton[IMAGES];
         JButton             toggleButton  = new JButton("Toggle scaling");
         boolean            doScale       = true;
         public Test()
              JFrame f = new JFrame();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel p = new JPanel(new GridLayout(1, IMAGES));
              for (int i = 0; i < IMAGES; i++)
                   p.add(this.buttons[i] = new JButton());
              f.add(p, BorderLayout.CENTER);
              f.add(this.toggleButton, BorderLayout.SOUTH);
              this.toggleButton.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e)
                        Test.this.refresh();
              f.setSize(600, 300);
              f.setVisible(true);
              this.refresh();
         public void refresh()
              this.doScale = !this.doScale;
              for (int i = 0; i < IMAGES; i++)
                   ImageIcon image = new ImageIcon(i + ".gif");
                   if (this.doScale)
                        image = new ImageIcon(image.getImage().getScaledInstance(180, 180, Image.SCALE_AREA_AVERAGING));
                   image.setImageObserver(this.buttons);
                   this.buttons[i].setIcon(image);
                   this.buttons[i].setSelectedIcon(image);
                   this.buttons[i].setDisabledIcon(image);
                   this.buttons[i].setDisabledSelectedIcon(image);
                   this.buttons[i].setRolloverIcon(image);
                   this.buttons[i].setRolloverSelectedIcon(image);
                   this.buttons[i].setPressedIcon(image);
    Download the gif images here:
    http://djmadz.com/zombie/0.gif
    http://djmadz.com/zombie/1.gif
    http://djmadz.com/zombie/2.gif
    When you press the "Toggle scaling"button it switches between unresized (properly working) and resized instances of three of my gif images. Notice that the left image almost never appears, the middle image always, and the right image most of the time. The right image seems to (almost) never animate. When you click on the left image (when visble) it disappears only when the backend is updating the animation (between those two frames with a long delay)
    Why are the original ImageIcon and the resized ImageIcon behaving differently? Are they differently organized internally?
    Is there any chance my way of resizing might be wrong?

    It does work, however I refuse to use SCALE_REPLICATE for my application because resizing images is butt ugly, whether scaling up or down. Could there be a clue in the rescaling implementations, which I can override?
    Maybe is there a way that I can check if an image is a multi-frame animation and set the scaling algorithm accordingly?
    Message was edited by:
    Zom-B

  • Animated GIF frame loss

    I have an applet that has a JPanel with a JLabel in it. That JLabel was created with an ImageIcon constructor with an animated gif image. The gif has eleven frames (each with replace set) and is set to loop. When I bring up the applet the image animates through the first 7 frames then stops. I can File/Open the gif in Netscape and it looks fine - animates all images and loops. Looking at it with:
    setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION); or FLASH_OPTION
    it looks good until that 7th frame then I start to see flash of grey the size of the JLabel.
    I understand that the ImageObserver defaults to the JLabel. But I have tried directly setting it with no joy. I have also tried calling .flush() on the image with no joy. So I tried a different animated gif and it stopped on the 3rd frame (but also appears fine in a browser).
    I am on day 2 of trying to figure this out (pulling my hair out).
    I cut this down quite a bit, so there may be syntax errors.
    public class RRR extends JApplet implements RRRConsts
    public void init()
    loadImages();
    myJPanel = new MyJPanel();
    contentPane.add(myJPael);
    private void loadImages()
    try
    problemImage = loadImage(new URL(getDocumentBase(),
    "problem.gif"));
    catch (Exception e)
    { logger.log(Level.SEVERE, "Unable to load images", e); }
    private Image loadImage(URL url) throws InterruptedException
    Image image = getImage(url);
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    return image;
    MyJPanel myJPanel = null;
    static Image problemImage = null;
    class MyJPanel extends JPanel implements RRRConsts
    MyJPanel()
    setLayout(null);
    setBounds(0,0,468,540);
    setOpaque(false);
    buildUI();
    private void buildUI()
    myLabel = new MyLabel();
    add(myLabel);
    private MyLabel myLabel = null;
    class MyLabel extends JLabel implements RRRConsts, ActionListener
    MyLabel()
    super(new ImageIcon(RRR.problemImage));
    }

    I just had the same problem. It seems that when using an animated gif as ImageIcon it will not be loaded compeltly if it is too large. The maximum seems to be somewhere between 60 - 70 KB.
    I managed to use a higher compression on my gifs to make them smaller, but I haven't found any general solution yet.

  • Animated GIF is running to fast

    I have an animated GIF in my Java app, and it seems to be running really fast for some reason. When the GIF is just placed in an HTML page to view it runs at the normal speed.
    Any help?
    Thanks.

    I know the topic is a little bit old, but I am seeing this issue as well. Since no answer was ever posted, I thought I would bring it up again. I have several animated gifs that play normally in a web browser, but when I try to display them in Java, they play extremly fast. I am just adding an ImageIcon, the animated gif, to a JLabel and setting the ImageIcons ImageObserver to the label. This technique worked in 1.3 but appears to be broken in the 1.4 releases. I have 1.4.1_02 installed right now.

  • Animated .gif not reloading

    Here's my problem:
    I'm trying to run an animation whenever a certain button is pressed. The file is an animated .gif. It works... but only the first time. I'm trying to figure out how to work more than once. The image is being loaded in a JLabel. Suggestions? Any help is greatly appreciated.
    some small parts of my code that may help:
    private static ImageIcon sinkHoop = new ImageIcon("images/sinkhoop.gif");
    private static JLabel hoopLabel = new JLabel(hoop);
    public void animateSinkHoop()
    hoopLabel.setIcon(sinkHoop);
    }

    I guess I've stumped everyone here.Today, everyone's stumped. But in the not so distant past:..
    http://forum.java.sun.com/thread.jsp?forum=31&thread=340088

  • Animated gif resizing problem

    Im trying to achieve the following: showing an animated gif that resizes to fill the area of a canvas. I tried the easy way: adding a label and setting the icon for that label, but when trying to resize the image it doesnt show (see code below). Is there any particular way of resizing an animated gif? can the labe-icon approach be used with animated gif that must be resized?
    Thanks a lot in advance.
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Image;
    import javax.swing.ImageIcon;
    public class TestFrame extends javax.swing.JFrame {
    /** Creates new form TestFrame */
    public TestFrame() {
    initComponents();
    Image image = this.getToolkit().getImage("C:\\multivideo\\img\\39.gif");
    Dimension dim = jLabel1.getPreferredSize();
    image = image.getScaledInstance(dim.width, dim.height, Image.SCALE_SMOOTH);
    ImageIcon i = new ImageIcon(image);
    jLabel1.setIcon(i);
    jLabel1.setBackground(Color.BLUE);
    pack();
    /** This method is called from within the constructor to
    * initialize the form.
    private void initComponents()
    jLabel1 = new javax.swing.JLabel();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel1.setIcon(new javax.swing.ImageIcon("C:\\multivideo\\img\\40.gif"));
    jLabel1.setMaximumSize(new java.awt.Dimension(1436, 86));
    jLabel1.setMinimumSize(new java.awt.Dimension(1436, 86));
    jLabel1.setPreferredSize(new java.awt.Dimension(1436, 86));
    getContentPane().add(jLabel1, java.awt.BorderLayout.CENTER);
    pack();
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new TestFrame().setVisible(true);
    private javax.swing.JLabel jLabel1;
    }

    I don't think getScaledInstance is smart enough to return a scaled image.
    You could try doing your own scaling:
    import java.awt.*;
    import java.awt.geom.*;
    import java.net.*;
    import javax.swing.*;
    public class Animated extends JComponent {
        private Image image;
        private double scale;
        public Animated(URL url, double scale) {
            image = new ImageIcon(url).getImage();
            this.scale = scale;
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            Graphics2D g2 = (Graphics2D) g.create();
            g2.translate(insets.left, insets.top);
            g2.scale(scale, scale);
            g2.drawImage(image, 0, 0, this);
            g2.dispose();
        public Dimension getPreferredSize() {
            Insets insets = getInsets();
            int w = insets.left + insets.right + (int)(scale*image.getWidth(null));
            int h = insets.top + insets.bottom + (int)(scale*image.getHeight(null));
            return new Dimension(w,h);
        public static void main(String[] args) throws MalformedURLException {
            URL url = new URL("http://members.aol.com/royalef/sunglass.gif");
            final JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new Animated(url, 2), BorderLayout.NORTH);
            f.getContentPane().add(new Animated(url, 1), BorderLayout.SOUTH);
            f.pack();
            SwingUtilities.invokeLater(new Runnable(){
                public void run() {
                    f.setLocationRelativeTo(null);
                    f.setVisible(true);
    }Or you could explicitly extract the images from the animated gif and
    resize them individually. The sample code here does the extraction:
    http://forum.java.sun.com/thread.jspa?forumID=20&threadID=500348

  • 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

  • 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
    }

  • Animated .gif in JPanel

    Hello,
    I'm trying to render an animated .gif in a JPanel. I'm overriding paintComponent as follows:
       public void paintComponent(Graphics g)
          super.paintComponent(g);
          // center the background image.
          //backgroundImage is an Image
          if (backgroundImage != null)
             g.drawImage(backgroundImage, (this.getWidth() - backgroundImage
                   .getWidth(this)) / 2, (this.getHeight() - backgroundImage
                   .getHeight(this)) / 2, this);
       }The problem: I'm only getting the first frame displayed. What do I need to do to properly display the animated image?
    Thanks.
    Marc

    Adding a JLabel is not convenient, nor is it the proper way to do it. The panel has other components and coming up with a layout manager that will overlay components is not the proper thing to do.
    Creating a Thread is also not the proper thing to do.
    I found a solution that works fine. Instead of using an Image, I create an ImageIcon and use that to display the animated gif.
       public void paintComponent(Graphics g)
          super.paintComponent(g);
          // center the background image.
          // backgroundImage is an ImageIcon
          if (backgroundImage != null)
             g.drawImage(backgroundImage.getImage(), (this.getWidth() - backgroundImage
                   .getIconWidth()) / 2, (this.getHeight() - backgroundImage
                   .getIconHeight()) / 2, this);
       }Thanks for your help.

  • Animated gif moving to fast

    I am trying to display an animated gif in a JLabel. My problem is that for some reason the animated gif speeds through the frames, instead of moving at the speed it was created at. Any idea what might be causing it.
    Below is the code I'm using to display the animated gif.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.JDialog;
    import java.io.*;
    public class loadingScreen extends JDialog
         private JLabel loadingLabel;
         ImageIcon loadIcon = new ImageIcon("images/animated_loading.gif");
        This function makes the loadingScreen a dialog box which, when
        opened, limits the user to be only able to use this window until
        they close it.
         public boolean startLoadingScreen()
              Window owner = (Window) getParent();
              Dimension d = getSize();
              Rectangle r = owner.getBounds();
              int x = r.x + r.width/2;
              int y = r.y + r.height/2;
              setBounds(x, y, d.width, d.height);
              getCenter();
              setVisible(true);
              return true;
        This function is called by an outside program. It takes in the owner
        frame information. It takes in a string that will be the title of
        the dialog box.
         public loadingScreen(Frame owner,String title,boolean modality)     
              super(owner, title, modality);          
              displayWindow();
        This function makes the gui for the window
         public void displayWindow()
              setResizable(false);
              Box groupBox = Box.createVerticalBox();
              loadingLabel = new JLabel(loadIcon);
              groupBox.add(loadingLabel);
              Container dialogPane = getContentPane();
              dialogPane.setLayout( new FlowLayout() );
              dialogPane.add(groupBox);
              pack();
         private void getCenter()
              Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
              Rectangle frame = getBounds();
              setLocation((screen.width - frame.width)/2,(screen.height - frame.height)/2);
    }

    Thanks for the help. Once I editied the gif file everything worked fine. As a side note, I used Gimp to edit the file and when I tried saving it had a funny message. "Delay inserted to prevent evil CPU-sucking anim."
    Thanks for the help.
    Ricky

  • 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 on createCustomCursor

    Hello All,
    I am trying to show an animated gif on one of my custom cursors using :
    Toolkit tk = Toolkit.getDefaultToolkit();
    try{
    myFrame.setCursor(
    tk.createCustomCursor(ImageIO.read(this.getClass().getResourceAsStream("test.gif")),new Point(15,15),"MyCursor" ) );
    catch(Exception e){}But i always see a static image for that gif.
    And when i try to use the same Image to show it on a JLabel something like this :
    ImageIcon ii = new ImageIcon(this.getClass().getResource("test.gif"));
    JLabel label3 = new JLabel(ii);I see the animated image here.
    Can someone help in showing the animated gif on the customcursor.
    I have tried using the below discussion for reference but it didnt help for animated images.
    http://forums.sun.com/thread.jspa?threadID=267944
    Thanks for your time.

    Hello,
    But i always see a static image for that gif.[http://java.sun.com/javase/6/docs/api/java/awt/Toolkit.html#createCustomCursor(java.awt.Image,%20java.awt.Point,%20java.lang.String)]
    Note that multi-frame images are invalid and may cause this method to hang.--------
    Here is another approach:
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import javax.swing.*;
    class AnimatedCursorTest {
      private javax.swing.Timer animator;
      private JButton button;
      private Toolkit tk    = Toolkit.getDefaultToolkit();
      private Cursor[] list = new Cursor[3];
      private URL url00 = getClass().getResource("32x32_00.png");
      private URL url01 = getClass().getResource("32x32_01.png");
      private URL url02 = getClass().getResource("32x32_02.png");
      private Point p   = new Point(0,0);
      public JComponent makeUI() {
        list[0] = tk.createCustomCursor(tk.createImage(url00), p, "00");
        list[1] = tk.createCustomCursor(tk.createImage(url01), p, "01");
        list[2] = tk.createCustomCursor(tk.createImage(url02), p, "02");
        animator = new javax.swing.Timer(100, new ActionListener() {
          private int counter = 0;
          public void actionPerformed(ActionEvent e) {
            button.setCursor(list[counter]);
            counter = (counter<list.length-1)?counter+1:0;
        button = new JButton(new AbstractAction("Start") {
          public void actionPerformed(ActionEvent e) {
            JButton b = (JButton)e.getSource();
            if(animator.isRunning()) {
              b.setText("Start");
              animator.stop();
            }else{
              b.setText("Stop");
              animator.start();
        button.setCursor(list[0]);
        JPanel p = new JPanel(new BorderLayout());
        p.add(button);
        p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
        return p;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          public void run() { createAndShowGUI(); }
      public static void createAndShowGUI() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new AnimatedCursorTest().makeUI());
        frame.setSize(320,240);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

  • Animated Gif help

    I want to place an animated gif into an application. I want it to start of not animated then I click a button and it starts. I click another button and the animation stops? Where do I start?
    I have placed the gif into a JLabel and it starts animating.
    Thats all I know how to do
    Help!

    Ok, So far I have one image, animated gif. There are 2 copys of that with different names in my dir. Search1.gif and Search2.gif. I place search1 into a custome JPanel that just paints the image, no animation, second inmage in a JLabel, show animation. I start with the no animation image showing, ok, click a button and image dissappears, ok, add animation image, not ok. My custom image panel with gif is in a JPanel, the JLabel will also be added to the same JPanel
    searchPane.remove(image1);
    searchPane.repaint();
    searchPane.add(image2);
    ...code here...
    searchPane.remove(image2);
    searchPane.add(image1);

Maybe you are looking for

  • ITunes opening without being clicked on

    I did a quick search and couldn’t find any information about this problem, but if it’s already been addressed, just post the link. My problem: Ever since I updated to iTunes 5.0.1, iTunes will open unexpectedly without being clicked on. I can quit it

  • HT1338 What the **** is going on here? Trying to upgrade fron Lion to Mountain Lion and Nothing id going right.

    Mountain Lion did not download – another instance of Lion did. No way back (inforrned that " upgrade codes" provided by Apple) were were already used),

  • About gcc !!Please come in!!help me!!!

    I have install gcc-2.95.2-sol8-intel-local. #pkgadd -d gcc-2.95.2-sol8-intel-local then add /usr/local/bin&/usr/ccs/bin to PATH It seems that gcc is working well. I can run ./configure successfully,but run 'make' unsuccessfully,even to say 'make inst

  • Unable to transfer files over network

    Hi all I'm trying to transfer some folders from my MBP to my iMac over a wireless network, but I get a series of 3 error messages when I try it. First I get "You may need to enter the name and password for an administrator on this computer to change

  • 1131 config issue, not connecting.

    im at a loss, i have setup a 1131 with multiple ssid's, they show up, but neither one will connect. i need 2 ssid's, one open and one protected. this is the config i have so far: version 12.3 no service pad service timestamps debug datetime msec serv