I can't get an animated GIF animated within a CLabel. I also tried Label.
final CLabel lblSpinner = new CLabel(this, SWT.NONE);
lblSpinner.setImage(SWTResourceManager.getImage(Installation_4.class, "/resources/spinner_anim_16.gif"));
What's wrong? Only the first GIF is displayed. In RCP I have to animate programatically but in RAP this must be a job for the browser I thought.
The following snippet works with RAP, with both Label
and CLabel
:
public class AnimatedGifSnippet implements IEntryPoint {
public int createUI() {
Display display = new Display();
Shell shell = new Shell( display );
shell.setLayout( new GridLayout() );
Image image = createImage( display, "resources/loading.gif" );
Label label = new Label( shell, SWT.NONE );
label.setImage( image );
shell.layout();
shell.open();
return 0;
}
private Image createImage( Display display, String resourceName ) {
ClassLoader classLoader = getClass().getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream( resourceName );
if( inputStream == null ) {
throw new IllegalArgumentException( "Resource not found: " + resourceName );
}
try {
return new Image( display, inputStream );
} finally {
try {
inputStream.close();
} catch( IOException exception ) {
// TODO handle exception
}
}
}
}
If this doesn't work with your image, then the problem is in the image image itself. Otherwise, you must be doing something wrong in your SWTResourceManager.getImage()
method. Please note that if you construct an Image
from ImageData
, these will only contain a single frame of the animated gif.