Animated GIF in SWT table/tree viewer cell

In a recent question I asked for input on how to implemented animated GIFs in SWT table/tree viewer cells. Below is some code of the final solution.

Animation thread

The animation thread can be asked for the “current frame index” (CFI) by interested parties. The CFI thusly denotes the frame of an animated GIF which should be rendered. LabelProviders are the interested parties in this context because they actually render the images.

The thread increments the CFI in its run method. Also, Display#asyncExec is triggered in the run method. During the async execution the table/tree is ask to redraw and update – see lines 69ff.


I use my own implementation of an OwnerDrawLableProvider which paints a static image if the icon doesn’t have to be animated. If it needs to be animated (based on some attribute of the row’s input) it paints the frame of an animated GIF. The index of the frame to draw is determined by the animation thread shown above. Hint: the getImage() method is called by paint().


The controller is responsible to start/stop the animation thread. Basically, whenever the viewer’s input changes the running animation thread must be canceled and a new thread must be started. The best hook for that is the viewer’s content provider – an implementation of I<Tree|Table>ContentProvider as it declares an inputChanged() method.

The code presented here was implemented for H2Eclipse, the Hudson plugin for Eclipse.

3 thoughts on “Animated GIF in SWT table/tree viewer cell

  1. Hey, thanks for the example, although not complete.
    What is an IJob there and what is the purpose there?


    1. Got it to work anyway, thanks for sharing.
      Here I had to issue a global tree update (no clientArea reduction), otherwise my GIF was getting animated only when hovering the tree __line__ with the mouse. Any idea why this is happening?

Leave a Reply