SWT standalone examples setup
Adding SWT to your workspace
- Download SWT for standalone applications. A standalone version of SWT is available
on the same download page as the Eclipse SDK. Look for the section titled
SWT Binary and Source. Do not extract the archive file, just save it to disk.
- Select Import... from the File menu.
- Select Existing Projects into Workspace and click on the Next button.
- Select Select archive file: and use the Browse button to locate the SWT
standalone archive you have previously downloaded.
- Click on the Finish button.
Importing example source
- Download and install the Eclipse Example Plug-ins. The Eclipse Example Plug-ins are available on the same
download page as the Eclipse SDK. Look for the section titled Example Plug-ins.
You can install the examples in the same location as you installed Eclipse or you can choose
a different location. If you install the examples in the same location as Eclipse, the example views
and editors will show up in your Eclipse environment (e.g. Windows > Show View ... > Other ... > SWT Examples
If the SWT example views do not appear right away in your menu, restart eclipse with the -clean argument).
This is fine but it is not necessary.
- Select New > Project ... from the File menu.
- Select Java Project and click on the Next button.
- Give the java project a name such as "SWT Examples".
- Select Create project from existing source and click on the Browse ...
button to locate the following directory:
eclipse/plugins/org.eclipse.sdk.examples.source_3.1.0/src/org.eclipse.swt.examples_3.1.0
- Click on the Next button.
- Click on the Projects tab and click on the Add button.
- Place a check beside org.eclipse.swt and click on the OK button.
- Click on the Finish button.
At this point your SWT examples should be compiled without any errors. Check the Problems
view for errors. If you get an error like "java.lang.Object
not found" it means
you have not configured a JRE. Go to the Window > Preferences ... dialog
and select the Java > Installed JREs preference page. Ensure that a JRE is installed
and that the path to the JRE is correct.
Running the Example
Now you can run the SWT standalone examples.
- Open the Java perspective.
- In the Packages view, select the main class that you want to run.
For example, the main class for the Address Book example is
org.eclipse.swt.examples.addressbook.AddressBook
.
- Select Run > Run As... > Java Application from the main menu.
Consult the documentation of each individual example for the name of
its main class and additional details.
The following examples are included in the swtexamples.jar
: