SWT is similar to JDK's AWT/swing. It relies on the implementation of the GUI control of the local operating system to create a Java GUI control. The difference between SWT and AWT/swing is that SWT uses many native window widgets, hence the name of SWT (standard Small Window Toolbox.
Because of the inherent complexity of the Window widget System and the differences between different systems, it is difficult to implement and maintain the Window widget library of the platform even in ideal conditions. Currently, several technologies can significantly reduce the complexity of the problem. SWT libraries use the underlying implementation technologies in these technologies. The SWT provided by ECLIPSE uses JNI to call the internal API of the operating system, so it can achieve the same appearance as the local application. In addition, SWT can also establish a one-to-one relationship between calls to the operating system of Java methods. In fact, this is one of the most important factors for SWT success.
The following is the configuration process for using SWT in Eclipse:
Step 1: whether creating a project or an existing project, you only need to add the SWT Library to the project to use SWT. Add the file/Eclipse/plugins/org. Eclipse. SWT. win32.win32. x86_3.1.1.jar to libraries in the project properties.
The installation directory of eclpse in the current directory above.
Step 2: Find the directory Eclipse/configuration/org. Eclipse. osgi/bundles/5/1/. CP, copy the file swt-win32-3139.dll to C:/Windows/system32.
After completing the above two steps, you can start the SWT application under eclipse. The following is an example of SWT, which is from p268 in eclipse programming technology and instance. The Code is as follows:
Import org. Eclipse. SWT. SWT;
Import org. Eclipse. SWT. Widgets .*;
Public class mylabel ...{
Private Label mylabel;
Private shell;
Private display;
Public mylabel ()
...{
Super ();
Display = New Display ();
Shell = new shell (Display );
Shell. setsize (200,200 );
Mylabel = new label (shell, SWT. None );
Mylabel. setbounds (38,21, 100,18 );
Mylabel. settext ("Hello, world! ");
}
Public void start ()
...{
Shell. open ();
While (! Shell. isdisposed ())
...{
If (! Display. readanddispatch ())
...{
Display. Sleep ();
}
}
}
Public static void main (string [] ARGs )...{
Mylabel label = new mylabel ();
Label. Start ();
}
}
Run the following command to see a window, which is exactly the same as the window application!
Of course, it is also possible not to use SWT for development in eclipse. The method is also the same as above, add the corresponding. jar to the directory specified by classpath or the lib directory of the current project. copy the DLL file to the C:/Windows/system32/directory. The difference is that you only need to download a SWT library.
Eclispe version 3.1.1 In this article