Designing the interface with SWT in eclipse

Source: Internet
Author: User

excerpted from http://www.tulaoshi.com/n/20160129/1488574.html

Designing the interface with SWT in eclipse

1. Why use SWT?

SWT is a cross-platform GUI Development toolkit developed by IBM. As for why IBM has struggled to develop a GUI toolkit on its own, rather than using Sun's existing Java GUI framework, which is composed of AWT, Swing, Java, Java, and so on, it's a long story. (remember reading a joke about the origins of SWT on a BBS).

Prior to SWT, Sun had provided a cross-platform GUI development Kit AWT (Abstract windowing Toolkit). Although the AWT framework also uses the native widget (native widgets), it has not been able to break through the LCD problem. LCD problems have led to the loss of some of the main platform features. If you don't understand (I don't understand), in other words, if platform A has a window part (widgets) 1–40 and Platform B has a window widget (widgets) 20–25, the cross-platform AWT framework can only provide the intersection of these two widget sets.

To solve this problem, Sun has created a new framework. This framework no longer uses the native widgets, but instead uses the emulation widgets (emulated widgets). This approach solves the LCD problem and provides a rich set of widgets, but it also brings new problems. For example, the interface appearance of a swing application is no longer similar to that of a native application. While these swing applications have achieved the greatest performance improvements in the JVM, they still have performance problems that their native counterparts do not have. Also, swing applications consume too much memory, so swing is not suitable for small devices such as PDAs and mobile phones.

IBM has tried to solve the above problems with the AWT and swing frameworks. Eventually, IBM created a new GUI library, which is SWT. The SWT framework accesses native widgets through JNI. If a widget cannot be found on the host platform, SWT automatically simulates it.

   2. The composition of the SWT application

A basic component of an SWT application is the display screen, the command interface (the shell, which enables the command to enter and make the operation Initialize), and the Widgets (Widgets). Display is responsible for managing the event loop and controlling communication between the UI thread and other threads. A shell is a window that is managed by the operating system Window manager in an application. Each SWT application requires at least one display and a shell instance greater than or equal to 1.

(This article from the teacher's website, more please visit http://www.tulaoshi.com)

Figure 1: SWT application from a different perspective
Figure 1 shows the SWT application from a different perspective. The diagram on the left is an inheritance diagram of a simplified UI object. The middle diagram shows the container structure of the UI object (containment structure). The diagram on the right is the UI appearance after creation.

If an application uses multiple threads, each thread uses the display object assigned to its own instance. The programmer can use the static method Display.getcurent () to get the currently active instance of the display object.

The shell is used to perform the window in a particular operating system. The shell can be maximized, minimized, or normalized. There are two types of shells. The 1th is a high-level shell, which is a subwindow of display, and it is also a main window. The 2nd class is the dialog shell, which relies on other shell windows to exist. The shell window eventually becomes the type mentioned above to see what style bits (style bits) are passed to the Shell constructor when the shell is created. The default value for a shell is Dialogshell. That is, if there is no argument, then the default is a dialog shell. If you assign a display object to a parameter, the shell will be a high-level shell.

The properties of some widgets must be set at the beginning of their creation. The properties of these widgets are the previously mentioned style bits (style bit). In the SWT class, the style bit is defined as a constant. For example, button button = New button (shell,〈stylebits〉). You can use the or (or) operator ' | ' To set multiple style bits. For example, if you want to set a push button with a border, you need to pass Swt.push | Swt. Border as a style bit parameter.

   3. Environment settings prior to SWT development

For SWT application development, you need to add the SWT library to the Classpath (CLASSPATH) and set the necessary environment variables.

First, you will find the Swt.jar library file in the Eclipse_homeeclipsepluginsorg.eclipse.swt.win32_2.1.0wswin32 directory. Note that the "org.eclipse.swt.win32_2.1.0" directory here is related to the version of Eclipse. I can't find you. Use the file search function. Then open the following window in turn project-〉properies-〉javabuildpath-〉libraries-〉add Variable-〉eclipse Home-〉extend Add the Swt.jar file to the classpath.

Next, you'll want to compile this SWT application. However, the run exception shown below appears. This exception occurs because the Swt.jar library is using a native library. You need to set the JAVA.LIBRARY.PATH environment variable to use the native library in Java.

The console output is as follows:

Java.lang.UnsatisfiedLinkError:no swt-win32-2136 in Java.library.path
At Java.lang.ClassLoader.loadLibrary (Unknown Source)
At Java.lang.Runtime.loadLibrary0 (Unknown Source)

Source: http://www.tulaoshi.com/n/20160129/1488574.html

Designing the interface with SWT in eclipse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.