My blog has moved!

You will be automatically redirected to the new address. If that does not occur, visit
http://utku-utkan.appspot.com/
and update your bookmarks.

Pages

Tuesday, April 22, 2008

Handling Animated GIFs with GWT

GWT provides an interesting mechanism to deal with images called image bundle. "An image bundle is a composition of many images into a single image, along with an interface for accessing the individual images from within the composite." However this creative approach has a problem. When you use an animated GIF in a page, you just see a normal image with no animation. If you really need an animated GIF, then you should use the com.google.gwt.user.client.ui.Image class. Below is an example snippet demonstrating the use of com.google.gwt.user.client.ui.Image class. For this example, assume that there is a an animated GIF named ajax-loader.gif inside the public folder of your application.

package org.hoydaa.gwtimage.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;

public class GWTImage implements EntryPoint {

    public void onModuleLoad() {
        Image image = new Image("ajax-loader.gif");
        RootPanel.get().add(image);
    }

}