JFileChooser animated gif preview

I'm using an Accesory with an ImageIcon to preview images on a JFileChooser.
It works ok, but I would like to know how do I get those animated gif to restart their animation whenever I click some other file (so the image preview goes to null) and click back on them.
There are non-looped gifs and looped ones, it is specially for the non-looped gifs as to give a way to get to see the animation again. After clicking the file once the animation never plays again, even if a load another preview by clicking another file and then go back...
Since there's no obvious method on ImageIcon or Image I tried flush since it says it clears the data but the only thing I got was the gif animating improperly (it would get trash/noise).
* JFileChooserImagePreview.java
* Created on 16 de junio de 2005, 12:58 AM
package ptcg.win.util;
import javax.swing.*;
import java.beans.*;
import java.awt.*;
import java.io.File;
/* from FileChooserDemo2.java. */
public class JFileChooserImagePreview extends javax.swing.JComponent implements PropertyChangeListener {
     public JFileChooserImagePreview(JFileChooser fc) {
          setHeight = -1;
          setWidth = -1;
          setPreferredSize(new Dimension(100, 50));
          fc.addPropertyChangeListener(this);
     public JFileChooserImagePreview(JFileChooser fc, int setHeight, int setWidth) {
          this.setHeight = setHeight;
          this.setWidth = setWidth;
          setPreferredSize(new Dimension(setHeight, setWidth));
          fc.addPropertyChangeListener(this);
     public void propertyChange(PropertyChangeEvent e) {
          boolean update = false;
          String prop = e.getPropertyName();
          //If the directory changed, don't show an image.
          if(JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
               file = null;
               update = true;
          } else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)) {
               file = (File) e.getNewValue();
               update = true;
          //Update the preview accordingly.
          if (update) {
               thumbnail = null;
               if(isShowing()) {
                    loadImage();
                    repaint();
     public void loadImage() {
          if (file == null) {
               thumbnail = null;
               return;
          ImageIcon tmpIcon = new ImageIcon(file.getPath());
          if (tmpIcon != null) {
               Image i = tmpIcon.getImage();
               //i.flush(); //screws the animation
               thumbnail = new ImageIcon(i.getScaledInstance(setHeight, setWidth, Image.SCALE_SMOOTH));
     protected void paintComponent(Graphics g) {
          if (thumbnail == null) {
               loadImage();
          if (thumbnail != null) {
               int x = getWidth()/2 - thumbnail.getIconWidth()/2;
               int y = getHeight()/2 - thumbnail.getIconHeight()/2;
               if (y < 0) {
                    y = 0;
               if (x < 5) {
                    x = 5;
               thumbnail.paintIcon(this, g, x, y);
     ImageIcon thumbnail = null;
     File file = null;
     int setHeight, setWidth;
}Thanks in advance

Never-mind. I have it working properly now.

Similar Messages

  • Viewing Animated GIF files in Preview

    Hello...
    I'm trying to figure out why I cannot view animated GIF files within Preview. When I search within Preview's help I get this...
    *1. Open the animated GIF file in Preview.*
    *2. If the window's drawer isn't already visible, choose View > Drawer.*
    *The drawer contains a thumbnail image for the animated GIF. The number of frames in the animation appears in the lower-right corner.*
    *3. Click the triangle beside the thumbnail image.*
    *Preview shows all the frames in the animated GIF. When you click a frame, the animation stops and Preview displays that frame.*
    Now at the end of number 3 it states that "the animation stops", so according to that statment Preview should be "playing" the animation until I click a certain frame to stop it. Well mine doesn't do this, SO what's going on?
    Oh, my OS is v10.4.10 and Preview is v3.0.9(409).
    Thanks!

    Preview in Panther did play animated gifs, although it was a bit clunky at it. Evidently they intended to fix this in Tiger, but instead they ended up breaking it completely. To play an animated gif you now need to do so in a browser, such as Safari. Preview no longer plays them at all.
    Francine
    Francine
    Schwieder

  • Viewing animated GIFs in the Finder and Preview

    I was wondering why my animated gif images do not play while I view them in the preview in the Finder or Preview. I know it plays when I view gifs in Explorer and was wondering why doesn't the Finder/Preview.
    I would really like to be able to view the animated gifs without having to open either Safari or Fire Fox to view them.
    Thanks

    Welcome to Discussions.
    Apparently Preview lost that functionality a few versions ago. And Quicklook also doesn't seem to do it. Someone said that Pathfinder plays them, http://www.cocoatech.com.
    If you don't want to use a "big" program like Safari or Quicktime, then your best bet is to use a quick and easy image viewer like Xee http://wakaba.c3.cx/s/apps/xee.html.
    Set it as default application by selecting a gif file, press cmd-I. Choose Xee under Open with and click Change all.
    /p

  • Viewing animated gifs in preview

    Anyway to view animated gifs in preview, or is there just some "play" or "animate" button i'm just not seeing?

    The Tiger version of Preview was supposed to work better with animated gifs than the Panther version. Unfortunately instead of improving it they broke something and it doesn't work at all. Thus far no fix has come out in the Tiger updates. Send Apple feedback:
    http://www.apple.com/macosx/feedback/
    The more people who complain the more likely it is to get fixed.
    Francine
    Francine
    Schwieder

  • Why doesn't Preview.app show me animated .gifs?

    I made an animated .gif with Macromedia Fireworks and it opens up perfect on a Windows Platform. But on my MacBook only the first frame opens and stays still as a single image.
    Once I open the .gif, in the Preview's Drawer, it shows me all of the single images that are supposed to be seen continously as an animation. But I repeat, no animation is played back.
    Help please, thank you.
    MacBook 13" Black   Mac OS X (10.4.8)  

    This is from the preview help document. What you are seeing is what is described for preview.
    Viewing animated GIFs
    An animated GIF is a graphic file that shows a short animation. Preview lets you look at each frame in the animation as an individual still image.
    Open the animated GIF file in Preview.
    If the window's drawer isn't already visible, choose View > Drawer.
    The drawer contains a thumbnail image for the animated GIF. The number of frames in the animation appears in the lower-right corner.
    Click the triangle beside the thumbnail image.
    Preview shows all the frames in the animated GIF. When you click a frame, the animation stops and Preview displays that frame.
    Mort

  • Why are animated gifs not displaying animations in the preview?

    Why are animated gifs not displaying animations in the preview?
    My coworkers and I are not seeing a animation in the preview pane in Adobe Bridge CS6 even when clicking the play button in the preview window. However, we do see a graphic of the first frame and one person sees 1 frame when clicking play and one other frame and then the animation stops, however, that is not the complete animation.
    I'm using Windows 7 32 bit
    My coworkers are using a mac.
    One coworker has apple OS Mountain Lion with a Intel Quad-Core Xeon – 64 bit system.
    Is this fixable or in the works as a patch? Otherwise we have to open these docs in a browser in order to view them properly.

    I've just come to the realization that some animated gifs do play fine and others do not. A coworker of mine suggests that if it's an animation made via Adobe Photoshop, it'll work in bridge but will not if it's made using something else.

  • Why don't animated GIFs open in Preview now?

    Before updating to Yosemite, animated GIFS opened in Preview. Now, I get a box telling me that it may be damaged or use a file format that Preview doesn't recognize.  I have never had any issues before, and these are all images used before. Please advise.

    With the bookmarks that open in the Sidebar ''(small section of the browser on the left)'', right-click those bookmarks and select '''Properties'''. Un-check '''''Load this bookmark in the sidebar''''', them click Save.
    That box becomes check-marked when the user uses a button on a web page for "Bookmark this Page". Best to use the Bookmark this Page feature within Firefox, rather than buttons on web pages.
    [https://support.mozilla.org/en-US/kb/use-bookmarks-to-save-and-organize-websites#w_how-do-i-create-a-bookmark How do I create a bookmark] <br />
    You can also use '''{Ctrl + D}''' from the key board.

  • Does Preview Run Animated GIFs?

    Greetings!
    I've 10.4.11 and though Preview's Help section says it views(runs) animated gifs I've found no way to do so ever since Panther. What's the trick -- if any?
    Thanks!
    JimWG

    Hi Jim,
    It doesn't animate in my 10.4.11 Preview, but drop it on or open it with any Browser, like Safari, or get GraphicConverter for even more options...
    http://www.macupdate.com/info.php/id/263

  • Edit animated gif

    Hi,
    How can I edit an animated gif in Photoshop Elements 6 for Mac?
    When I open the file there is just the first frame in one layer - no other layers available.
    Thanks!

    Thanks Barbara!
    Barbara B. wrote:
    ... then bring it to PSE.
    I can't drag the single frames from Preview to PSE, because PSE 6 doesn't run in window mode.
    (Is this improved in the current version?)
    I can only drag the single frames to the desktop (as TIFF files, I guess transparency info is lost then?).
    Barbara B. wrote:
    ... there's a bug beginning in PSE 6 where you can't change the frame delay rate from the default when you save an animated gif.
    What's the default frame delay rate? Maybe it's just what I need.
    Barbara B. wrote:
    You might  want to look into a free program like giffun from stone.com instead.
    Yes that's maybe a better idea. It doesn't have to be free software. Can you recommend something good?
    Thanks again!

  • .gif preview slow in Save for Web

    I am having an issue in Save for Web where the .gif animation preview works very slow and choppy. I am an advertising designer and many times I need to work on animated .gif banners. I am working with Photoshop CS6. When I play the animation in the frame timeline the animation speed works as intended, a little choppy but the timing isn't too bad. However when I go into the Save for Web screen and play the animation it always appears a lot slower and looks choppy. Anything se to 0.0 or No Delay runs as if its set to .1 seconds. Now if I export the file and open it in Chrome the animation speed seems to go back to normal. This wasn't always the case, I tested this 2 or 3 months ago and the animation speed in the export was also slow and choppy but it must have been fixed in one of the updates since then.
    My issue is I don't want to have to preview everything in Chrome after I export it, and then possibly have to go back and tweak it then save again, preview again etc. I have never encountered this issue in previous versions on Photoshop or other machines. Ususally my experience has been the opposite, the frame timeline has always been slower, but previewing in Save fro Web has shown a pretty accurate preview.
    I also have a HP laptop running Windows 7, photoshop CS6 and I don't encounter this issue at all. It seems that everyones default answer on all of the forums is "different browsers handle .gif animation speeds differently, etc.." but int he past I have saved a .gif on my mac and it was slow and choppy in the Chrome, then I saved the same file on my PC transfered it back to the mac and previewed in Chrome and the animation played quickly and smoothly.
    I can't see it being a hardware issue because the machine I am using is farily new. iMac Late 2013/2013, 3.4 Ghz Intel Core i7, 16GB RAM, NVIDIA GeForce GTX 675MX 1024 MB, running OSX 10.8.4 Mountain Lion.
    Could it possibly be a setting or preference that needs to be changed? As I stated above it seems that now when I export the animation works fine in the browser the preview is just slow, but I have read that many people are having this issue so hopedully someone will have a solution.

    I don't use a Mac but the first the first thing I do when I have performance problems with Photoshop on my PC is to do some house cleaning.  I reset my Photoshop Preference to a saved copy I made when Photoshop was working well.  I Also clean my disk up clearing caches and temp files so the plenty of scratch space.  I close all applications and look at the machine CPU utilization. Then try Photoshop to see if it is back to its normal performance.

  • Keynote 3: Transparent Animated GIF Problems

    I've been trying to get an animated GIF with a transparent background to run in Keynote, but it's giving some disastrous results.
    I produce the animation by rendering the frames as PNG (with alpha channel) in MegaPOV 1.2.1. Then I use the convert utility from ImageMagick 6.2.9 to make them into an animated GIF.
    When I drop the animated GIF into Keynote 3.0.2, the first frame shows fine (with transparency and all). But when I animate it, the background goes red (the main color in this particular movie) and some trace of the previous frames stays. It seems like:
    1. Rather than displaying the GIF frame-by-frame, each frame is getting layered onto the previous frames.
    2. Keynote doesn't like the alpha channel for some reason.
    Problem 1 is also present if I open the GIF in Preview (is that supposed to be the correct behavior of an animated GIF?). Problem 2 seems to be Keynote-specific.
    Any suggestions for a work-around on this? The animated GIFs work fine if rendered without the alpha channel, but it'd look so much better with transparency!
    iMac 2GHz Intel Core 2 Duo   Mac OS X (10.4.9)  

    MegaPOV doesn't have a GIF output option. The choices are PNG, Targa, PPM, and hdr (not familiar with that last one). I don't know if PPM even has alpha-capability.
    So in some way, I have to convert PNG to GIF. The tools I have to do this are ImageMagick and Gimp. I tried them both, then viewed the results using several programs. Results are tabulated below -- (1) means that problem 1 from above was apparent (ie, parts of the previous frames were visible under the current frame); (2) means that problem 2 was visible (ie, the transparent parts took on some background color).
    If I didn't know how to change the default white background in the program, I couldn't tell whether problem (2) occurred, since the movie made with Gimp had a white background in Keynote.
    Using ImageMagick 6.2.9 to convert PNG->GIF and animate GIF:
    * viewing with Safari 2.0.4 : (1), can't tell for (2)
    * viewing with Preview 3.0.9 : (1), can't tell for (2)
    * viewing with Firefox 2.0.0.3 : (1)
    * viewing with Keynote 3.0.2 : (1), (2) -- alpha goes red
    Using Gimp 2.2.11 to convert PNG->GIF and animate GIF:
    * viewing with Safari : (1), can't tell for (2)
    * viewing with Preview : (1), can't tell for (2)
    * viewing with Firefox : (1)
    * viewing with Keynote : (1), (2) -- alpha goes white
    I only converted the first few frames using Gimp, since I was doing it by hand.
    All of this makes me wonder whether I'm dreaming the impossible, since problem (1) is universally present. It also makes me pretty sure that problem (2) is Keynote-specific.
    If there are any other tools that will convert/animate GIFs on a modern Mac, I'd love to hear about them. My UNIX-y tools seem to be failing me here. The Mac tools I remember from "back in the day" -- GIFBuilder and GIFConverter -- seem to have been abandoned around the beginning of Mac OS X. GIFBuilder won't even load my files, and GIFConverter still lacks alpha support in PNG.

  • Does animated .gif export support animation of library symbols?

    I'm currently using the 30-day free trial of Adobe Flash Professional CC. I was really pleased to see how easily you could export animations in animated .gif format, seemed to run without a hitch.
    One thing I noticed while using Flash is that instances of symbols placed into a scene don't actually animate when you use the "Play" function -- that is to say, when you press Enter and the playhead starts moving along the timeline from its current position. They remain at the very first frame of their respective animations. In order to show the proper animations of symbols, you have to use the Test function (CTRL - Enter) to actually compile a working .swf of the thing.
    This wasn't much of an issue until I tried to export in .gif format and I got this same issue. Instances of symbols don't animate, they only seem to work in compiled .swf's.
    FileDropper link to the working file I'm using: http://www.filedropper.com/flashbottle
    Result .gif: http://i.imgur.com/PZVXST7.gif
    Since the use of symbols in the Flash workflow seems to be a rather common occurrence it seems unthinkable that Flash wouldn't support their usage with whatever mechanism they use to export animated .gif's. Is there some sort of silly mistake I'm making or checkbox I need to toggle? Or is the functionality simply not there?

    Thank you for your reply!
    I check exported GIFs in various browsers and XnView viewer.
    It's definitely not a preview  issue - i have 32Gb of RAM and Nvidia Quadro 4000 GPU on my system.
    I believe the issue is with transparency, because i'm able to export GIFs with solid background just fine
    GIF export dialogue window has 'Transparency' checkbox, so it looks like it should be possible to export an animated GIF with transparent background, but for some reason i'm getting all frames at the same time
    thank you

  • Question on Animated GIF Timing

    I have a weather-type animated GIF, and believe me, it is not
    my choice or
    idea, but anyway I need to get this working.
    Here it is:
    http://www.sendto.org/temp/weather-cvia.gif.
    In this animation, all the frames are set to 100 but the
    timing is not
    smooth. No idea why. When I change frame 2 to 50, the timing
    seems to me
    to be closer to even, but it makes no sense to cut the time
    on frame 2 to
    have all frames display for equal time. Is anyone else seeing
    this?
    The source file is here:
    http://www.sendto.org/temp/weather-cvia.png
    Many thanks,
    Tony

    Hi Anthony:
    Are you testing the playback in a browser? The FW playback -
    at one time
    anyway - was not a reliable method for previewing.
    Have you checked to make sure there are not several frames
    identical to
    frame 2 in the animation? That too would give the impression
    that frame
    2 is staying up longer.
    Jim Babbage - .:Community MX:. & .:Adobe Community
    Expert:.
    Extending Knowledge, Daily
    http://www.communityMX.com/
    CommunityMX - Free Resources:
    http://www.communitymx.com/free.cfm
    .:Adobe Community Expert for Fireworks:.
    news://forums.macromedia.com/macromedia.fireworks
    news://forums.macromedia.com/macromedia.dreamweaver
    Anthony Bollinger wrote:
    > "Linda Rathgeber **Adobe Community Expert - Fireworks**"
    <[email protected]>
    > wrote in message
    news:[email protected]...
    >> The lower the number, the faster and smoother the
    animation. It needs more
    >> frames to make it really smooth.
    >
    > Linda! Thanks for the reply!
    >
    > I sort of get what you are saying . . . but I guess I
    don't understand why
    > the numbers for each frame don't work. I don't have the
    "raw materials" to
    > supply frames in between the existing ones, although I
    might be able to work
    > up something. But let me make sure we are connecting.
    >
    > I think you are saying the animation takes "jumps" --
    that is fine as far as
    > what is needed. The whole problem is those jumps are not
    even, although I
    > have given fireworks identical numbers for each frame.
    We slowed the
    > animation down so that it would not be so annoying (it
    was originally set to
    > somewhere around 10 per frame and I changed it to 50,
    then 100).
    >
    > The whole problem with this animation is that frame 2
    displays for *longer*
    > than the other frames, even though I have told it to
    display just as long in
    > the PNG file. This must be a bug with either the
    exported GIF, the display
    > engine, or FW. Looks like the best way to fix it is to
    change the frame 2
    > value to 50, which is just a hack. I wondered if anyone
    has encountered
    > this before. There is nothing wrong with the PNG file,
    so this has to be a
    > bug.
    >
    > Thanks!
    > Tony
    >
    >

  • Animated GIF Export issues

    I have a simple Flash animation which I'd like to be made
    into a transparent GIF.
    When I do the GIF export, only the first frame of my
    movieclips (which are placed in the main timeline) get rendered. It
    seems like Flash only records the main timeline preview output into
    the GIF file, and does not play movieclip objects. You would expect
    the GIF recording to be of the same preview as when you hit
    ctrl+enter (essentially final playback).
    Because of this, the GIF export is pointless. The only way to
    use it is to have all your animations occur in the main timeline,
    and not within movieclips. It doesn't work for me (and for most
    people?), because I need to easily scale my animations, which is
    doable by just resizing a movieclip.
    Is there a way around this in Flash? Am I missing something?
    I've had to use a 3rd-party tool (Magic SWF2GIF) to do the
    GIF recording.
    My other issue is Flash cannot export transparent GIF's it
    seems. Because of this, I have to rely on more 3rd-party GIF tools,
    most of which are rubbish.
    In the end, I've had to take snap shots of every individual
    frame and edit each frame as individual files in Photoshop to do
    all the cropping and transparency just right. Real pain when you
    are talking 50 frames, and having to do multiple animations.
    Is there a way to export transparent GIF's in Flash?
    Seems kind of dumb that I have all this high-end software and
    loads of tools... and I still have to edit things frame by
    frame.

    Thank you for your reply!
    I check exported GIFs in various browsers and XnView viewer.
    It's definitely not a preview  issue - i have 32Gb of RAM and Nvidia Quadro 4000 GPU on my system.
    I believe the issue is with transparency, because i'm able to export GIFs with solid background just fine
    GIF export dialogue window has 'Transparency' checkbox, so it looks like it should be possible to export an animated GIF with transparent background, but for some reason i'm getting all frames at the same time
    thank you

  • Animated .gif not moving

    I've been intrigued by the new animated "postcards" or cinemagraphs (for example, see http://fromme-toyou.tumblr.com/tagged/gif). I found a great tutorial about how to do this using Photoshop Extended and the animation panel. I created my own, and then followed the instructions for saving the file:
    1. "Save for Web and Devices"
    2. make sure to save as GIF, looped "forever"
    When I previewed the gif (from the "save for web and devices" dialog box), it worked great.
    But when I save the gif, it doesn't move. It is just one frame of the animation, as a static photo. When I click the file, I get a "Preview" that shows all the frames, but I can't ever get it to move.
    Is there a step I'm missing? Or is there some operating system setting I need to change? I've never created an animated gif before, but I can see other people's animated gifs in my email. (I'm attaching my gif in case you can figure it out from that.)
    OKAY...I looked at the attachment, and it moves (my dog's eyes). This is the only time it has worked. I've tried to email it, post it on Tumblr, open it in my browser, but it never worked. Now, I post it here, and--at least as I look at the attachment--it works here. How can I get it to move when I post it online or try to send it via email?
    I'm running Mac OSX 10.6, Photoshop CS 5.1.
    Thank you!
    Carol

    Some email clients disable animated GIFs.
    Web sites like Tumblr that have image upload functions may further process your file during upload by removing its animated features. You could control this by hosting images on your own web site.
    In general, animated GIF files are not ideal for emails because of their large size. GIF is an inefficient format for photorealistic animation/video.

Maybe you are looking for

  • Create XML file from Oracle DB

    Hi, I'm working in a task to create electronic billing for Mexico Rules, to do this; I need to create a XML source that will contain all the information requested from Oracle DB. For this reason, I'm looking how to create this XML file from Oracle DB

  • How do you change the Print Products Store from USA to UK like you can do in IPhoto?

    How do you change the Print Products Store from USA to UK like you can do in IPhoto?

  • How to import photos photo booth

    Hi, I just did a clean install of mavericks. I have a folder of my previous photobooth images/videos. Can someone please explain to me how I can add these back in so that they show up in photo booth when I open that app? Thanks, Steve

  • How do I removed the downloaded music from my ipad in the Music app with effecting icloud music?

    My music was taking up too much space so I joined itunes match, but the 6 gigs of my music is still on my ipad. How do I removed the downloaded music from my ipad in the Music app without affecting icloud music? I clicked to replace all music with ic

  • Ref Curosrs in Oracle 8i

    Hi, Am currently using the Oracle 8i, i have return ref cursors in oracle 10g.. which is working fine.. but when am trying to use the same in Oracle 8i... am facing lot of problems.. could some one help me on this.. Please. Oracle 10g: CREATE OR REPL