In a previous article I already introduced you to SWT Stand alone Applications. In this article we’re actually going to build one.
While SWT is integrated as part of the Eclipse plug-in API, for standalone application development it is best to develop against the SWT standalone download. This document will help you get set up.
First, download the .zip of SWT for your platform from the SWT homepage.
The SWT .zip file can then be imported into your workspace. In the File menu, choose Import and select the Existing Projects Into Workspace wizard. (In newer versions of eclipse, you can find Existing Projects Into Workspace in the General category).
The illustrations with this article come from a Linux version of Eclipse but like with Java it doesn’t matter which platform you’re using. Just like the code, the documentation is portable.
Direct the wizard to the location where you downloaded the .zip file. This will create a project called org.eclipse.swt in your workspace.
Your Java projects can then add the SWT project as a dependency. Open the properties dialog of your Java project, and on the Java Build Path page, include the org.eclipse.swt project.
With the SWT project as a dependency, you can now benefit from Eclipse features such as the Javadoc view and code assist.
Now you can run any main class in your project by selecting the class and then selecting Run > Run As > Java Application.
The Standard Widget Toolkit (SWT) is a graphical widget toolkit for use with the Java platform. It was originally developed by Stephen Northover at IBM and is now maintained by the Eclipse Foundation in tandem with the Eclipse IDE. It is an alternative to the Abstract Window Toolkit (AWT) and Swing Java graphical user interface (GUI) toolkits provided by Sun Microsystems as part of the Java Platform, Standard Edition (J2SE). Both SWING and AWT have always been criticized for their slowness. They actually ‘draw’ GUI components on screen pixel by pixel, which slows down the building up of screens.
This is different for SWT which accesses the native GUI libraries of the operating system using Java Native Interface (JNI) in a manner that is similar to those programs written using operating system-specific application programming interfaces (APIs). Programs that call SWT are portable, but the implementation of the toolkit, despite part of it being written in Java, is unique for each platform.
The results are Native Speed Applications for Mac, Windows
and Linux. Probably the best example is the SWT Webbrowser. An SWT example which is included in the Eclipse IDE and is used by Eclipse to show its help documents.
Thanks for reading this article. If you’re interested in the details of building SWT Applications see the next article .