Let's JFace It!!

If you're still using SWT's Shell class for implementing your windows
frame. I think it's time to take a serious look at JFace's
ApplicationWindow class.

Unlike Shell, ApplicationWindow can be legally subclassed although it is
possible for the Shell to be subclassed but you will pay the price later
in terms of interoperability and cross-platform"ness".

ApplicationWindow can be implemented like a JFrame. let's look at code
snippet below.


//start of snippet
import org.eclipse.jface.window.ApplicationWindow;


public class MyApp extends ApplicationWindow{

}//end of snippet



Since JFace is a high-level UI tool, it eases up the burden of writing
Window UI code by avoiding low-level SWT Shell codings without
necessarily hiding it. Another snippet shows how this works.



//start of snippet
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.widgets.Shell;

public class MyApp extends ApplicationWindow{

public MyApp(Shell shell){
super(shell);

}

//we have to configure the Shell by overriding configureShell()
protected void configureShell(Shell shell){
super.configureShell(shell);
//now let's put a window title ala VB
shell.setText("Manila Coders Rules!!!");
//put your other composites here.

}

public static void main(String[] args){
//notice how simple it is than implementing a low-level
//Shell main class.

Display display = new Display();
Shell shell = new Shell(display);
MyApp myApp = new MyApp(shell);
myApp.setBlockOnOpen(true);
myApp.open();
Display.getCurrent().dispose();

}
}//end of snippet


Alternatively, you can set the window title like this:



getShell().setText("Manila Coders Rules!!!");



Next time I will show how to add status bar at the bottom with less pain
and greater flexibility.

Comments

Popular Posts