The Java Developer's Guide to Eclipse The Java Developer's Guide to Eclipse

In Chapter 14, The Standard Widget Toolkit: A Lean Mean Widget Machine, you learned the fundamentals of SWT. The project com.ibm.jdg2e.swt.snippets makes available nearly 250 examples representing all facets of SWT. These short examples or snippets come directly from the SWT component on eclipse.org (see SWT Snippets). To run them you must download the individual snippets to your workspace. For your convenience, these snippets are repackaged on the book's CD-ROM in a single, searchable Java project with the snippets grouped into packages that match the grouping on the web site. The only modification was to give each snippet a unique class name and assign them to packages.

The Javadoc contains the descriptions of all the packages and each snippet class. These snippets, as the name implies, are short, rarely more than a page of code and often less. They range from a SWT "Hello World" example to more esoteric examples you may rarely need. In between are many useful examples that demonstrate the breadth of this component.

Running the SWT Snippets

  1. Import the snippets project com.ibm.jdg2e.swt.snippets into your workspace according to the instructions in the readme file on the CD-ROM.
  2. Note: You might notice three unexpected files after importing this Java project: manifest.mf, snippets.jar, and snippetssrc.zip. Is this plug-in project? Technically, yes, but if you examine the plug-in manifest you will see that it only serves to make the SWT library contained in plug-in org.eclipse.swt available during build. Since you could have imported this project using the import plug-in function the jar and zip files are present (you can delete them if you wish). Conversely, if you were to import this project as a plug-in you will see a superfluous src directory since snippetssrc.zip was used instead. You can delete this secondary src directory if you want.

  3. Select a snippet and run it using the Run as > SWT Application (or Debug as > SWT Application) context menu or workbench menu.

    Example Snippet102

Roadmap of the SWT Snippets

Start by examing the Javadoc overview. Each package contains a group of one or more snippets that illustrate some aspect of SWT like tables, browser, or swing interoperability. Note that snippets not focused on SWT widgets generally display a simple gray screen. You will need to explore the code to understand what the snippet code is illustrating.

References

Overview and package list

© Copyright International Business Machines Corporation, 2004, 2006.
All rights reserved.