Eclipse - Standard Widget Toolkit (SWT) - Installation

SWT, the Standard Widget Toolkit, will help us to draw windows for the Java platform.

On this webpage you will find links to download last stable releases http://www.eclipse.org/swt/

Once downloaded, open Eclipse, right click on the Explorer tab, then : Import... > General > Existing Projects into Workspace.
Click Next then select the Select archive file option and browse until, for example for Windows OS, your  swt-3.7.1-win32-win32-x86.zip file.

Click Finish.

Now in your Package Explorer you can see the org.eclipse.swt project.

Right click in this Explorer to create a new Java project named for example project1.

Right click on project1 > Build Path > Configure Build Path > Java Build Path.
On the right there are several tabs.
Select Projects and click Add...
Select org.eclipse.swt and click OK.

You project project1 is now linked with SWT and you can use its classes.

laugh

Comments

Comment: 

Thank You Mi-K !!!

HelloWorldSWT  which is the 1st example of SWT given after the installation of Eclipse does not work on Windows (I just tested it on Seven).

Yypically you get those errors:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
    no swt-win32-3738 in java.library.path
    no swt-win32 in java.library.path
    Can't load library: C:\Users\<YourUserName>\.swt\lib\win32\x86\swt-win32-3738.dll
    Can't load library: C:\Users\<YourUserName>\.swt\lib\win32\x86\swt-win32.dll

    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:285)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:194)
    at org.eclipse.swt.internal.C.<clinit>(C.java:21)
    at org.eclipse.swt.widgets.Display.<clinit>(Display.java:138)
    at HelloWorldSWT.main(HelloWorldSWT.java:13)

After  the download  of swt-3.7.1-win32-win32-x86.zip and by following the above given explanations by Mi-K, it just works.

By the way  you can find swt-3.7.1-win32-win32-x86.zip for example here:

http://eclipse.ialto.com/eclipse/downloads/drops/R-3.7.1-201109091335/

 

Comment: 

Yes, this fix worked for me as well. Thanks for that!

Comment: 

They should add this step to the tutorial  :-D

Comment: 

Yes this does work - in my eclipse you have to right click on your project and select "Properties" and then navigate to the build path screen.

Thank you!

Comment: 

Thank you so much, these steps fix my problem.

Comment: 

Hi, it does not works now.

Eclipse says "Some projects cannot be imported because they already exist in the workspace". Please, help!

Comment: 

Hello Kostyanus,

Just rename your project with another name or delete it from your computer.

cool

Comment: 

I am trying too import missing
Can't load library: C:\Users\Admin\.swt\lib\win32\x86_64\swt-win32-4427.dll
Can't load library: C:\Users\Admin\.swt\lib\win32\x86_64\swt-win32.dll
but still facing with error. Any idas?

Comment: 

Done. Import is finished.
But now error has chenged.

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Display cannot be resolved to a type
Display cannot be resolved to a type
Shell cannot be resolved to a type
Shell cannot be resolved to a type

Java text is:

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class HelloWorldSwt {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);

shell.setText("Hello, world!");

shell.open();
// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in the event queue
display.sleep();
}
}
display.dispose();
}
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.