Using animated GIF as JButton icon

Hi,
I am trying to use an animated gif as an icon in a JButton.
Everything works as it should except the animation is static!!
Screenshots and code are at:
http://www.beammicrosystems.com/Java/JButton.html
Anyone got any good ideas?
Regards,
Andrew

well i think you can do this in a label you can watch for a animation like you want a gif so my idea is that you should just make the label as a button and them :
JLabel label = new JLabel();
label.setIcon = new ImageIcon("name.gif");
and put it the setBounds
label.setBounds(x,y,long,tall);
and if you want that looks like a button just do this
label.setBorder(BorderFactory.createRaisedBevelBorder());
thats all.

Similar Messages

  • Datagrid using animated gif or flash

    I have a datagrid that is using an image control for its item
    renderer on one of the columns. That works just fine but I would
    like to be able to display an animated image in the datagrid
    instead of a static one.
    I know flex doesnt support animated gifs but is there any way
    I could make it show one in a data grid?
    Thanks.

    If you are web deployed you can put an animated gif as the image to an iconic button.
    Image items cannot display animated gifs.
    Anything else you can do through a JavaBean if you need to.

  • Using animated gif...

    I've encountered a problem in displaying animated gif using java Swing.
    For my program, I need to display 6 animated gif images. Sometimes I would get all those displayed, but sometimes only 1 or few are displayed.
    This problem troubles me until I found that it is the problem of animated gif I've used, because I have tried to replace the animated gif to static ones then every time the images are all displayed.
    I need a help urgently. Thanks a lot in advance.

    Hi
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class Dance extends JFrame 
    public Dance()  
         addWindowListener(new WindowAdapter()
        {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);}});
         getContentPane().setLayout(null);
         setBounds(10,10,400,300);
         JLabel j1 = new JLabel(new ImageIcon("cut1.gif"));
         j1.setBounds(10,30,40,40);
         getContentPane().add(j1);
         JLabel j2 = new JLabel(new ImageIcon("cut2.gif"));
         j2.setBounds(50,70,40,40);
         getContentPane().add(j2);
         JLabel j3 = new JLabel(new ImageIcon("cut3.gif"));
         j3.setBounds(90,110,40,40);
         getContentPane().add(j3);
         JLabel j4 = new JLabel(new ImageIcon("cut4.gif"));
         j4.setBounds(130,150,40,40);
         getContentPane().add(j4);
         setVisible(true);
    public static void main (String[] args)
         new Dance();
      Noah

  • Using animated gifs  in emails

    I've made an animated gif using flash an am trying to make it
    so the gif appears in my signature at the bottom of every email. I
    can place it in the signature but when I send the email the gif is
    static and doesn't move. Also I'm using a mac and when I recieve an
    animated gif in an email from a PC the gif is also static. I need
    to be able to send animated gifs in emails from PC and Mac using
    Mircosoft Outlook for PC and Entourage for MAC. Any help would be
    much appreciated.
    Cheers,

    this really has nothing to do with flash at all - you have no
    control over this as the recipient of
    your email may not be using an email client that supports
    animated gifs - does your gif work when
    viewed ina web page?
    you must realize there are a myriad ways people check email -
    sometimes via a browser, handheld
    device, email client software, etc...not all support animated
    gifs and the ones that do may have
    that option turned off by user.
    i would consult the support section of the email software
    your recipients use.
    --> **Adobe Certified Expert**
    --> www.mudbubble.com
    --> www.keyframer.com
    Luke H wrote:
    > I've made an animated gif using flash an am trying to
    make it so the gif
    > appears in my signature at the bottom of every email. I
    can place it in the
    > signature but when I send the email the gif is static
    and doesn't move. Also
    > I'm using a mac and when I recieve an animated gif in an
    email from a PC the
    > gif is also static. I need to be able to send animated
    gifs in emails from PC
    > and Mac using Mircosoft Outlook for PC and Entourage for
    MAC. Any help would be
    > much appreciated.
    >
    > Cheers,
    >
    >

  • Using animated gifs with transparent background.

    Hi guys,
    Keynotes 6.2.
    I have been onto apple support with this problem.
    I add a transparent animated gif to my project.
    It show as a movie correctly in the presentation but when exported as quicktime or HTML the movies fail.
    We eventually found out that quicktime does not support animated gifs. ( support.apple.com/kb/ht3775 )
    So I exported the animation onto a folder with all the frames separately and brought them into final cut pro.
    I then followed these tutorials on how to export with transparent background. ( http://provideocoalition.com/mspencer/video/fcp-x-and-alpha-channels and http://www.larryjordan.biz/fcp-export-transparency ).
    I now have a quicktime movie that if I bring back into Final Cut Pro it has a transparent background.
    However when I bring into keynotes it still has a black background. (presumably keynotes does not recognise the  Apple Prores 444).
    Any ideas how I can achieve what I need. ?
    I am using a program called crazytalk animator and can output with transparent background. Animated Gif or a series of image stills BMP, JPEG, TGA or PNG.
    Cheers
    SteveW

    This has been an ongoing issue for me since I switched from Powerpoint to Keynote. Most of the animated gifs with transparent backgrounds that I used with Powerpoint are no longer transparent in Keynote. You may want to search for those earlier threads on this topic...
    To summarize: I've had to open up my animated gifs in After Effects and use the Color Key effect to restore transparency, with mixed success.
    Good luck!

  • Possible to Use Animated GIF as Rollover Image?

    Before I spend a lot of time on development...does anyone
    know if it's possible to use an animated GIF as a rollover image in
    Captivate? I'm developing an e-Learning course for a
    Sarbannes-Oxley application, and I want to be able to hover over an
    object, then have a rollover graphic describe the hover target in
    more detail...the catch being that I want the description to look
    like a scrolling stock ticker.
    I'm sure Flash is probably the ideal development environment
    for this idea, but that project is way beyond my Flash skills at
    this point...
    Thanks!

    I know you can load and display a PNG image just the way you do for a GIF/JPEG one :
    ImageIcon myIcon = new ImageIcon("my_icon.png");but I don't think many others formats are recognized by j2se... you can simply try to load a BMP file to find out.

  • Animated gif on JButton is not working

    Hi all,
    I have a JButton, which is used as a 'search button'. I want my search button to show an animated globe gif when search is going on. I have my code as below.
    JButton searchButton = new JButton(MyUtilities.searchIcon());
    ImageIcon animatedGlobe = MyUtilities.animatedGlobeGif();
    searchButton.setPressedIcon(animatedGlobe );
    At runtime the button is showing a static globe which is not animating.
    Can any one please answer what could be the problem?
    Thanks in advance,
    amar

    Thanx Demanic ,
    I am doing swings for first time. Can you please tell me how to repaint the button using seperate thread?
    Thanks,
    amar

  • Animated gif icon for an exception instead of the standard icon?

    Hello,
    is there a possibillity to use an animated gif icon for an exception instead of the red standard icon in a web template?
    I tried  to change the standard icon s_s_ledr.gif against an animated gif icon in the mime repository, but it does not work. In the IE the icon is still shown without animation.
    Maybe I´ve changed the wrong icon?
    Can you please help me?
    Greetings
    Andreas
    Edited by: Andreas Zenner on Feb 25, 2009 1:22 PM

    Hi Andreas,
    it is possible to integrate own symbols for exceptions. If you can use animated gif I don't know. However there is a post over here explaining the usage of the modification for symbols:
    Re: BI 7 Web Design API - Parameter modification - Exception symbol
    If you have questions just let us know.
    Brgds,
    Marcel

  • Disabled JMenuItem doesn show animated gif

    Hi there
    I would like to have a popup menu with actions that are enabled after they have finished with some background task taking some time. Basically this works fine for the enabling action on a shown popup. However, adding an animated gif as the icon or disabled icon does not show it in disabled state. In enabled state it works perfect. Please have a try with the sample code. You should see the disabled item for 2 secs and the icon is not showing up. After being enabled, it does. Invoking the menu again shows the animated gif in its last state left, but not moving any more.
    I guess, repaints are not done appropriately in disabled state... Any ideas how to solve that would be highly appreciated :-)
    Actually I used the icon at http://mentalized.net/activity-indicators/indicators/pascal_germroth/indicator.white.gif
    Cheers
    Daniel
    public class Main
      public static void main(String[] args)
        final JFrame frame = new JFrame();
        frame.addMouseListener(new MouseAdapter()
          public void mousePressed(final MouseEvent e)
            final JPopupMenu popup = new JPopupMenu();
            popup.add(new JMenuItem("Open..."));
            popup.add(new JMenuItem("Close"));
            final JMenuItem action = new JMenuItem("Long loading until enabled");
            action.setIcon(new ImageIcon("C:/spinner.gif"));
            action.setDisabledIcon(new ImageIcon("C:/spinner.gif"));
            popup.add(action).setEnabled(false);
            popup.show(e.getComponent(), e.getX(), e.getY());
            SwingUtilities.invokeLater(new Runnable()
              public void run()
                try
                  Thread.sleep(2000);
                  action.setEnabled(true);
                catch (InterruptedException e1)
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 200);
        frame.setVisible(true);
    }Edited by: daniel.frey on Apr 22, 2009 7:50 AM

    The problem is that you are causing the EDT to sleep, which means the GUI can't repaint itself. Read the section from the Swing tutorial on Concurrency to understand what is happening.

  • Animated gif layered above background image

    I have a static background image which is displayed in a JPanel. I need to display animated gifs at certain positions on the base image. For every new frame of the animation, the paint method is called whcih attempts to load the entire base image + all the new animated images which is extremely slow!. It also means the animated gif keeps on getting loaded, and seldom gets beyond the first frame.
    Im sure many people have had to do something like this. Is the solution to draw the gifs on the glasspane (or use layered panes), and to have a seperate paint method? or is their a simple approach like setting a special clip area.

    thanks for the help...
    The size of the background image is approx 400*400 pixels (gif or jpg), and the icons are 25*25, and have between 1 and 6 frames.
    Here comes the code... I havent finished with the mediatracker stuff, but youll get the idea Im sure.
      public void paint(Graphics g) {
        MediaTracker tracker = new MediaTracker(this);
        tracker.addImage(image,0);
        try {tracker.waitForID(0);}
        catch (InterruptedException e){}
        g.drawImage(image, 0, 0, this); //draw background image (approx 400*400 pixels)
        int ICON_ID = -1;
        Image img;
        //draw all the icons...
        //all icons have between 1 and 6 frames. 25*25 pixels.   
        for (int i = 0; i < icon_IDs.size(); i++) {
          try {
            ICON_ID = new Integer(icon_IDs.elementAt(i).toString()).intValue();
            Point p = dm.getIconPosition(ICON_ID);
            if (isAlarm(ICON_ID)) {        //ITS AN ALARM - use animated gif
              img = getAlarmImage(ICON_ID);
            else                          //NORMAL ICON - no animation
              img = DataDefinition.getImageIcon(dm.getIconType(ICON_ID)).getImage();
            tracker.addImage(img,0);
            try {tracker.waitForID(0);}
            catch (InterruptedException e){}
            int width = DataDefinition.getSize(dm.getIconType(ICON_ID)).width;
            int height = DataDefinition.getSize(dm.getIconType(ICON_ID)).height;
            g.setClip(p.x, p.y, p.x+width, p.y+height);
            g.drawImage(img, p.x, p.y, p.x+width, p.y+height, 0,0,img.getWidth(this),img.getHeight(this),this);
          catch (SQLException sqle) {
            System.out.println("Could not find position of icon : " + ICON_ID);
      }

  • I am having major issues importing Animated gif's into Adobe Captivate

    Hi everyone
    Captivate 7 (64 bit) keeps crashing when i import animate gifs into flash.
    It's a serious workflow issue for us as the project requires animated gifs.
    I don't have any files to supply for this query as i can't even import gif's into a blank doc.
    Has any one found a solution for this issue ?
    Adobe ??  Have you got a fix for this bug ?
    Thanks in advance
    Nick

    How were the GIF's created? Which version of 7 do you use, you can see the complete version number under Help, About Captivate.
    I have been using animated GIF's in 7, they were created with Photoshop. And I know that each frame in the animation has to have a duration that is not 0secs.

  • Animated GIF not cycling frames in Tomcat

    I have pages that use animated gif files to get across a point.
    In the IDE, they cycle the images as they should
    SunAppserver cycles them properly.
    I only get the first frame in Tomcat (5.5.7)
    Over on the java.net, I saw this on a page concerning JAI:
    GIF
    The decoder supports animated GIF files and GIF files with transparent background. Only the first frame of an animated GIF file may be loaded via JAI; subsequent frames must be obtained via direct use of the ancillary codec classes.
    Um, am I missing something, or is this a Tomcat problem ?

    You just need transparency in your file. Not sure if it has to be pre-multiplied. In graphic converter you need to remove the backgrounds. Haven't used GC in years so can't say how you can be sure it's gone but in Photoshop, Illustrator and After Effects you can choose to have a checkerboard background to tell you when you are seeing 'thru' the image and by how much (the overall opacity or mask of the whole image if that doesn't confuse the issue).
    If you are using PS images they will almost certainly generated with a set of rectangles including a perimeter cropping box and white background and these need to go either before it's bitmapped in a vector base app or the relevant pixels erased after it has been bit mapped in GC. As previously mentioned, if you have a unique bkgd colour, colour selecting/keying are some ways to do this). Much faster for >10 images to generate the plots without the bkgd but this may not be possible, what software is source material coming from?
    I regularly bring in vector based moving art-work into keynote with alpha from Adobe AE, Apple Quartz and rendered .mov files. Some codecs (H.264) don't support a separate alpha channel (RGBA) but PNG (slow to render) and animation and a bunch of others do. Pre-multiplying removes the A channel in the RGBA (by multiplying the R/G/B by the A values) thereby speeding and making compatible with some GPUs/render pipelines.

  • Animated GIF in JTabbedPane - repaint madness!

    Loading and animated GIF into the icon for a JTabbedPAne just works, but it causes the paintComponent method on the main part of the panel to be called repeatedly. Anyway to distinguish between the two areas? The icon repaints automatically but I don't want to have to repaint the rest of the panel unnecessarily.

    I've run into the same problem simon, the only way I came over this was to do my own animation for the gif. Bit of a bother really. Anyone have any other solutions?

  • Animated gif in splash hangs or very slow

    Hi
    Not new to programming but quite new to Java. I have tried to find information
    on this already but could not find it. If I missed it and have a double post here,
    please let me know the link to the other post.
    I have a application built in Java. On my laptop it starts in just 2 seconds.
    On the production machine (AMD Geode based touch panel) the application
    starts in about 30 seconds.
    Due to the startup time I wanted to just the -splash option from javaw.exe
    example:
    D:\dist>javaw -splash:animated.gif -jar hmi.jar
    The animated gif shows immediately and is 4532 bytes large.
    java -version gives the following output:
    java version "1.6.0_07"
    Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
    Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)
    But with the animated gif as splash the application takes 3 to 4 minutes
    to start or it does not start at all but only keeps showing the splash.
    If I use a non-animated gif the startup time is almost like the normal 30 seconds.
    Any known issues with startup performance using animated gif as splash,
    or are there any known issues on AMD Geode based systems regarding the
    startup performance and usage of animsted gifs as splash ?

    I just see that the splash is not removed from screen either.
    If I minimize the java application I see the animated gif still
    there on screen.
    I tried this with a normal gif (non animated) and that one
    is also not removed from screen when the application is started

  • Animated Gif Repaint

    I knew I was going to end up here eventually, stupid animated gifs.
    First of all, I get weird drawing artifacts on an animated gif on jkd 1.5, I upped this to 1.6 and everything is cool with displaying the gif. It could be because I'm running JBuilder in a XP VM. I don't really care how to fix this, or if its even fixable, I'm just pointing it out.
    I have an animated gif in an imageicon. The program is hangman, and the gif shows a stick figure walking up onto the podium to get hung. I would like to play the gif once, every time the "New Game" button is clicked. I have tried a variety of things to do so, including JLabel1.repaint(); calling the label again, etc, etc. I'll try to post the relevant bits of my code.
    public class HangFrame
        extends JFrame implements ActionListener {
      public HangFrame()
        try {
          jbInit();
        catch (Exception ex) {
          ex.printStackTrace();
      }jbinit calls the placement of all the items.
        jLabel1.setBounds(new Rectangle(19, 57, 550, 400));
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == start) {
          start();
    ....'start' is my name for the button that reads "New Game".
    The start method contains:
    ImageIcon maingif = new ImageIcon( (ClassLoader.getSystemResource(
            "hang1.gif")));
         jLabel1.setIcon(maingif);
    //I've been trying different stuff right here, like repaint.The image displays correctly, and runs once (per the setting I gave it in flash, or thats how java does it).
    I've searched extensively (seems I got lucky by just managing to get it to display once :D). I saw that I might have to flush the image or something like that, but I'm not really sure what that means. I've never had any experience with the graphics and paint component, most of the work we do in class is console and algorithm stuff. I got bored over break and made my hangman into a swing app. I'd appreciate any help.
    Oh, and sorry if this should be in the swing subforum, I figured my issue was too basic for it.
    Edited by: rpk5000 on Dec 31, 2007 8:52 AM

    rpk5000 wrote:
    This is where you're wrong. Dipshits like you post **** like this all the time when it's readily available information that can be searched for WITHOUT >hosing up our forums.Great, give me a link, or even a search term to use on google or these forums. Before you give me search terms, you might want to actually check and make sure the answer is somewhere there...are you out of your freakin mind?!?!?!
    go to google and type "java gif animation"
    you think you're the first person to want to do this?!?!
    moreover, search the forums here
    you think you're the first person to ask for this here?!?!
    You would think "repainting an imageicon animated gif java" would give a page that has the answer on it within the first 10 results but....
    I'm looking for a page that simply says, take your imageicon and call.... (repaint();) or whatever to make it run one more time.Did you even read the API for ImageIcon! It took me 2 seconds to find the information for animating gifs as imageicons.
    Well Java just sucks now doesn't it. Stop using animated gifs and Java since they suck. There, problem solved!I like Java a lot, I'm just saying, in certain instances it seems to fall short.No, YOU fall short. I found the solution in 3 seconds.
    This is a "New to Java" subforum, if you can't handle helping people in a pleasant manner, that shows you respect the other person, what do you think people will think of you and java. If I spent more time on forums like this, and was looking at which language to try, I doubt I would pick java.I don't care what you think of me OR Java. I'm tired of noobs wasting forum resources with this crap. Once I was new to everything, but I went to the library and when the internet came along i learned how to search it!
    Critical thinking people. Don't we teach this in schools any more?!
    When it becomes an Internet joke (http://thedailywtf.com/Articles/plz-email-me-teh-codez.aspx) about how bad the sun forums are, well, you really need to reconsider what you want to do with your life.
    LMAO! You are the daily WTF!
    Edited by: wpafbuser1 on Dec 31, 2007 1:52 PM

Maybe you are looking for