Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Redirect page

Archived:How to create a Splash Screen in eSWT

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

ESWT is a deprecated UI framework. It is not present on Series 40 and on Symbian there are better maintained UI frameworks for most functionality (e.g. LWUIT).

Article Metadata
Code ExampleTested with
Devices(s): S60 3rd Ed. FP2 SDK
Created: gorkem.ercan (26 Nov 2008)
Updated: skalogir
Reviewed: skalogir (22 Aug 2012)
Last edited: hamishwillee (31 Jul 2013)



This snippet shows how to create a splash screen using eSWT.The example implements the splash screen as a window that is not maximized, but rather floats in the currently active display window. It shows an image and also updates a Progress Bar.

Warning.pngWarning: This example doesn't properly work on Nokia Belle. Tested on Nokia PureView 808 running Belle Feature Pack 1 (112.020.0309). The splash screen is properly displayed but the loading bar fails to update itself

Source file

import javax.microedition.midlet.MIDlet;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
public class SplashScreenDemo extends MIDlet implements Runnable, SelectionListener {
// A handle to the eSWT UI thread created by this MIDlet.
private Thread UIThread;
// The eSWT Display created by this MIDlet in the eSWT UI thread.
// When this is created the MIDlet gets connected to the native UI
// functionality and eSWT UI toolkit is initialised for it.
private Display display;
// A Shell widget created by this MIDlet.
private Shell shell;
// A boolean to set when the event loop should exit.
private boolean exiting = false;
public void startApp() {
// Create the eSWT UI thread.
if(UIThread == null) {
UIThread = new Thread(this);
public void pauseApp() {
// Here we could reduce the resources but we should keep the Display
// instance and the eSWT UI Thread.
// destroyApp is called when the MIDlet is terminated from the task list
// with the clear key, or the end key is pressed when the MIDlet is focused.
// It might also be called when the system needs to close applications
// e.g. in low memory conditions.
public void destroyApp(boolean unconditional) {
// Make the event loop exit in the eSWT UI thread.
// Wait for the eSWT UI thread to die.
try {
} catch(InterruptedException e) {
// This method can be called from any thread to make the event loop to exit.
void exitEventLoop() {
exiting = true;
// The eSWT UI Thread.
public void run() {
// Create the Display.
display = new Display();
shell = new Shell(display);
Rectangle screenSize = display.getBounds();
final Image image = new Image(display, screenSize.width-50, screenSize.height/2);
GC gc = new GC(image);
gc.drawText("Splash Screen", 0, 5);
final Shell splash = new Shell(shell, SWT.ON_TOP);
final ProgressBar bar = new ProgressBar(splash, SWT.SMOOTH);
Label label = new Label(splash, SWT.BORDER);
FormLayout layout = new FormLayout();
FormData labelData = new FormData ();
labelData.right = new FormAttachment (100, 0);
labelData.bottom = new FormAttachment (100, 0);
FormData progressData = new FormData ();
progressData.left = new FormAttachment (0, 5);
progressData.right = new FormAttachment (100, -5);
progressData.bottom = new FormAttachment (100, -5);
Rectangle splashRect = splash.getBounds();
Rectangle displayRect = display.getBounds();
int x = (displayRect.width - splashRect.width) / 2;
int y = (displayRect.height - splashRect.height) / 2;
splash.setLocation(x, y);;
display.asyncExec(new Runnable() {
public void run() {
for (int i = 0; i < 10; i++) {
try {Thread.sleep(1000);} catch (InterruptedException e) {
// Execute the eSWT event loop.
while(!exiting) {
if(!display.readAndDispatch()) {
// Clean up and destroy the MIDlet.
public void widgetDefaultSelected(SelectionEvent e) {
public void widgetSelected(SelectionEvent e) {
// Exit command selected, exit the event loop.


The splash screen will appear for 10 secs and update the ProgressBar every second. And will make the main application screen visible.

See also

This page was last modified on 31 July 2013, at 06:02.
65 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.