he Eclipse Standard Widget Toolkit (SWT) is growing in popularity, as evidenced by its use in applications like Azureus
. In this 10-minute solution, you will learn how to make use of an SWT project template that can greatly reduce the time required to build small and medium-sized applications. In particular, the template offers the following features:
- A UI that Works Out of the BoxThe project already has a MainWindow class that comes complete with a menubar, toolbar, client area, status bar, and about dialog. The Open toolbar button and File menu item have code that opens a file dialog box, and the File | Exit menu option closes the app. (See Figure 1.)
|Figure 1. The basic template application, awaiting your modifications, is shown. |
- ExecutablesThe project has an Ant task that makes it trivial to build executable JARs, Windows .exe's, and Windows installers.
- Better HelpContext-sensitive SWT Javadocs are integrated into the template.
- PreferencesThe MainWindow saves its window size and location in a preferences file that your application can use.
- TextFileThe project includes a class that makes reading and writing text files trivial.
- CursorsA default (arrow) cursor and a waiting (hourglass) cursor have been added to the MainWindow class.
- PortableYou will be able to take your project to other computers and it will just work because the swt.jar and associated .dll are included in the project.
To give you an idea of the time savings you can expect to see using the template, consider a utility that I wrote recently. The application allows the user to select a directory for source code analysis. The application then parses all source code files in the directory and its sub-tree, and compiles information on the number of lines of code, comments, and white space for each file. From the time I began working on the application, to the time that the application was being installed on a colleague's computer, 50 minutes had passed. Of this, just under 40 minutes were spent on the tree-walking and source code parsing logic. Only 10 minutes were spent working on the user interface, building the executables, and creating an installertasks that could easily have taken hours to complete without the template.
The specific environment used to develop the SWT Project Template was Eclipse 3.2 (which includes Ant), JDK 6.0 and Windows XP (however, the basic steps can be adapted for use on *NIX and MacOS systems). Optional, but recommended, components include Jigloo GUI Builder 3.9, Launch4j 3.0, and NSIS 2.0.
You want to quickly build an SWT application, complete with a native executable and installer.
Start with the SWT Project Template, make a couple of simple modifications, then point-and-click to start the builder.