I have never known what SWT is and what SWT is. I have had time to do this over the past two days and it seems quite good. This article mainly records how to install and configure SWT. I want to record it in my own language even though the content is similar.
Step 1: download and install SWT.
SWT: http://www.instantiations.com/windowbuilderpro/
Registration machine: http://www.itpub.net/714132.html
Step 2: Install SWT. The installation process is relatively simple. You can proceed to the next step. Let's take a look at the usage of the registration machine. It's very tiring to write it;
Step 3: configure the SWT environment. If you want to use SWT in eclipse, you must add the SWT jar package to eclipse. Otherwise, even if you can use the SWT design interface, the classnotfound error will be reported when the program is running. During configuration, click "Windows/prefernces" on the eclipse interface, and click the Java/installed jres node in the list on the left. The current JDK is displayed on the right, select the currently used JDK, click the edit button, click the addexternal jars button, and add the following jar package in the file selection dialog box:
If the Plugins directory of eclpse is D: // myeclipse enterprise workbench 5.1.0 Ga/Eclipse/plugins, the jar package to be added is:
Org. Eclipse. SWT. win32.win32. x86 _ 3.2.1 . V3235.jar;
Org. Eclipse. SWT _ 3.2.1 . V3235e. jar;
Org. Eclipse. Core. commands _ 3.2.0 . I20060605-1400.jar;
Org. Eclipse. jface. Text _ 3.2.1 . R321_v20060810.jar;
Org. Eclipse. jface _ 3.2.1 . M20060908-1000.jar;
Org. Eclipse. Equinox. Common _ 3.2.0 . V20060603.jar
More than one jar package must be added. If one jar package is missing, SWT cannot be run or errors may occur.
The last step is to register the DLL file. There is a DLL file under the SWT plug-in directory, the file name on my local machine is swt-win32-3235.dll if the version used is different, it may lead to different file names, but are all swt-win32 -*. DLL format, copy the file to C:/window/system32, and then run regsvr32 [file directory] swt-win32-3235.dll in cmd, note that regsvr32 must be followed by a space, after you press enter, you should be prompted that the registration is successful. There are articles on the internet saying that you only need to copy the data to system32, but it must be registered on my machine before it can be used. There may be differences in operations.
[Update]: After completing the preceding steps, if you still cannot find the SWT package, check the JDK you are using, especially for friends who are using myeclipse, click windows-preferences-Java-install jars to see the JDK version used. If it is myeclipse, JDK under Weblogic is selected by default, change JDK to your local machine. For example, my local machine is C:/j2sdk1.4.2 _ 06.
After the above work is completed, the SWT installation process is complete. Next we can start the first SWT program.
Click Create -- projects in eclipse. A designer node is displayed in the list. Select SWT project;
Then, create a new windows application in the project by right-clicking the project node to select it;
Now you can design the GUI. The component panel is on the left. You can check the information for the specific component, because I just got in touch with it.
First, drag a button component to the Panel, and set all attributes to default. ,
Click the button object in the panel, and then click the event tab in the component panel on the left. The event list is displayed. Select the select node and select the wideselect event, you can understand this event as AWT. the actionlistener of the event. Double-click the text box to the right of the name. In this case, the system switches to the source interface. In the code interface, write the event processing:
Messagedialog. openinformtation (shell, "," hello, this is a SWT demo program ");
Press Ctrl + Shift + O to enable eclipse to automatically import the required package.
If you have not previously imported org. Eclipse. jface. text_3.2.1.r321_v20060810.jar and org. Eclipse. jface_3.2.1.M20060908-1000.jar, this event processing will become unavailable.
Click test designer windows in the upper left corner to view the design interface. Note that this interface is a preview interface, and event processing and other processing logic do not work.
After that, run it in eclipse to see the effect.
During my use, I encountered some strange errors. I listed them here, hoping to provide you with reference:
1. When you click Run, an error prompt box is displayed. The error message is fatal exception occurred program will exit. At the same time, the console reports an error:
Java. Lang. unsatisfiedlinkerror: No swt-win32-3236 in Java. Library. Path
At java. Lang. classloader. loadlibrary (classloader. Java: 1517)
At java. Lang. runtime. loadlibrary0 (runtime. Java: 788)
At java. Lang. system. loadlibrary (system. Java: 834)
At org. Eclipse. SWT. Internal. Library. loadlibrary (library. Java: 123)
At org. Eclipse. SWT. Internal. win32. OS. <clinit> (OS. Java: 18)
At org. Eclipse. SWT. Widgets. display. <linit> (display. Java: 125)
At test. Main (test. Java: 17)
If this problem occurs, copy the swt-gdip-win32-3236.dll and swt-win32-3236.dll to the C:/j2sdk1.4.2 _ 06/JRE/bin directory;
2. If the SWT interface is available when the program runs, but an error is reported in the console when you click the button, and the prompt is: Java. Lang. noclassdeffounderror: ORG/Eclipse/CORE/commands/common/eventmanager.
At org. Eclipse. jface. Resource. jfaceresources. getfontregistry (jfaceresources. Java: 267)
At org. Eclipse. jface. Window. Window. createshell (window. Java: 503)
At org. Eclipse. jface. Window. Window. Create (window. Java: 425)
At org. Eclipse. jface. dialogs. Dialog. Create (dialog. Java: 1124)
At org. Eclipse. jface. Window. Window. Open (window. Java: 785)
At org. Eclipse. jface. dialogs. messagedialog. openinformation (messagedialog. Java: 346)
At test $1. widgetselected (test. Java: 28)
At org. Eclipse. SWT. Widgets. typedlistener. handleevent (typedlistener. Java: 90)
At org. Eclipse. SWT. Widgets. eventtable. sendevent (eventtable. Java: 66)
At org. Eclipse. SWT. Widgets. widget. sendevent (widget. Java: 928)
At org. Eclipse. SWT. Widgets. display. rundeferredevents (display. Java: 3348)
At org. Eclipse. SWT. Widgets. display. readanddispatch (display. Java: 2968)
At test. Main (test. Java: 35)
The cause of this problem is the lack of Org. eclipse. core. commands_3.2.0.I20060605-1400.jar, the solution is to add the jar package in the install jars interface, the directory is. /Eclipse/plugins/org. eclipse. core. commands_3.2.0.I20060605-1400.jar. After adding the program, you do not need to restart eclipse to run the program correctly. In fact, I have been wondering that this jar is not added when SWT is configured for the first time, and the program can run successfully. This world is amazing.