SWT Examples

SWT Examples

SWT Examples are useful little programs that are written in SWT. These are typically much larger and more comprehensive than SWT Snippets.

The following SWT Examples can be downloaded from the Eclipse download page: ControlExample on Vista

  • ControlExample
  • CustomControlExample
  • AddressBook
  • BrowserExample
  • ClipboardExample
  • DNDExample (Drag and Drop)
  • FileViewer
  • GraphicsExample
  • HelloWorld [1-5]
  • HoverHelp
  • ImageAnalyzer
  • JavaViewer
  • LayoutExample
  • PaintExample
  • TextEditor
  • OLEExample (win32 only, OLE)
  • OleWebBrowser (win32 only, OLE)

ControlExample, CustomControlExample, LayoutExample, and PaintExample are also available as Eclipse plugins, and the following examples are only available as Eclipse plugins:

  • BrowserDemo in the org.eclipse.swt.examples.browser.demos project
  • WebBrowser in the org.eclipse.swt.examples.browser project

There are several ways to download and run the SWT examples:

Running the SWT Examples inside Eclipse

  1. To get the examples, go to the Eclipse downloads page at http://download.eclipse.org/eclipse/downloads.
  2. Click on the Eclipse build that you would like examples for (i.e. the Eclipse build that you are running; typically the latest Stable Build).
  3. Scroll down until you see "Example Plug-ins". Read the paragraph on installing them, and select the download for your platform.
  4. After installing the examples, you can find their source in eclipse/plugins/org.eclipse.swt.examples.<exampleName>.source_<version>.jar.
  5. To run the plug-in SWT examples, restart Eclipse, go to Window > Show View... > Other... and expand "SWT Examples".

Alternatively, you can use these (more detailed) steps from the Eclipse ISV doc to download, install, and run the Eclipse SWT Examples:

  1. Installing the examples
  2. Running the SWT examples as views or with the SWT Example Launcher
  3. Running the SWT standalone examples
  4. SWT Examples Overview

Launching standalone SWT Examples inside Eclipse

  1. Load SWT into your workspace.
  2. Load the SWT examples into your workspace by one of the methods listed above.
  3. Run a standalone example by selecting the main class (e.g. org.eclipse.swt.examples.controlexample.ControlExample) and selecting
    Run > Run As > Java Application (Note: prior to Eclipse 3.3 use Run > Run As > SWT Application).

Running standalone SWT Examples outside of Eclipse

(NOTE: these instructions will only work for Eclipse 3.3 and newer) To run the ControlExample or CustomControlExample standalone:

  1. Go to the Eclipse downloads page at http://download.eclipse.org/eclipse/downloads/.
  2. Click on the Eclipse build that you would like examples for (i.e. the Eclipse/SWT build that you are running; typically the latest Stable Build).
  3. Scroll down until you see "Example Plug-ins", download the .zip for your platform, and extract it to your local machine.
  4. In the directory with the extracted example plug-ins, find file org.eclipse.swt.examples_<version>.jar, and extract it in place.
  5. Open a DOS window (on Windows) or a terminal window (on Mac or Linux) and navigate to this directory.
  6. To run the example, type the following line with the appropriate paths substituted:
    <pathToYourJRE>\bin\java -classpath <pathOfYourPlatformSWTjar>;.\swtexamples.jar org.eclipse.swt.examples.controlexample.ControlExample

    This is the ControlExample. There is a tab for each control, and you can change the various styles, etc, to see what changes in the controls. To run the CustomControlExample simply use the class name CustomControlExample instead of ControlExample in step 6.