Eclipse

SWT Examples

SWT Examples

The following SWT examples can be downloaded from the eclipse download page:

  • 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)

The 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 download page: http://download.eclipse.org/eclipse/downloads/index.php
  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, the source for them will be in a src.zip file in the appropriate subdirectory of: eclipse/plugins/org.eclipse.sdk.examples.source_<version>/src/
    For example, the 3.1 source for the standalone examples in org.eclipse.swt.examples is in: org.eclipse.sdk.examples.source_3.1.0/src/org.eclipse.swt.examples_3.1.0/swtexamplessrc.zip.

  5. The examples in package org.eclipse.swt.examples run standalone, and the examples in org.eclipse.swt.examples.* packages are eclipse plug-ins.
  6. 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 > SWT Application (note: as of Eclipse 3.3 you should use Run > Run As > Java Application instead).
Running standalone SWT Examples outside of eclipse

(Note that these instructions will only work for eclipse 3.1 and newer). To run the ControlExample and CustomControlExample standalone:

  1. Go to the download page for the eclipse version you are running. For example, for eclipse 3.3 this is:
    http://download.eclipse.org/eclipse/downloads/drops/R-3.3-200706251500/index.php.
  2. Scroll down to the "Example Plug-ins" section, download the examples zip for your platform, and unzip it to the same place that you originally unzipped eclipse. Let's say that you unzip both eclipse and its examples to d:\ (answer Yes when it asks if you want to overwrite the license files).
  3. (If you are using eclipse 3.3 or newer then you can skip this step) Open the file d:\eclipse\plugins\org.eclipse.swt.win32.win32.x86_3.X.X.jar in winzip and extract the following 3 files into d:\eclipse\plugins
    • swt-awt-win32-XXXX.dll
    • swt-gdip-win32-XXXX.dll
    • swt-win32-XXXX.dll
  4. Open a DOS window and type:
    d:
    cd d:\eclipse\plugins\org.eclipse.swt.examples_3.X.X
  5. Type the following line: (if you are using eclipse 3.3 or newer then the -Djava.library.path argument can be omitted)
    <pathToYourJRE>\bin\java -classpath .;..\org.eclipse.swt_3.X.X.jar;..\org.eclipse.swt.win32.win32.x86_3.X.X.jar;.\swtexamples.jar -Djava.library.path=.. 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 5.