Using SWT to design the interface in eclipse

Source: Internet
Author: User
Tags thread

1. Why use SWT?

SWT is a Cross-platform GUI development toolkit developed by IBM. As for why IBM struggled to build a GUI toolkit on its own, rather than using the sun's existing Java GUI framework, composed of AWT, Swing, Java 2d, Java, and so on, that's a long story. (Remember to read in a BBS on the origin of swt jokes about the class of the post).

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

To solve this problem, Sun has created a new framework. Instead of using the native window widget, the framework uses the Emulation window widget (emulated widgets). Although this method solves the problem of LCD and provides a rich set of widgets, it also brings new problems. For example, the interface appearance of swing applications no longer resembles the appearance of native applications. Although these swing applications have achieved maximum 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 completely address the above issues with the AWT and swing frameworks. Finally, IBM created a new GUI library, which is SWT. The SWT framework accesses native window parts through JNI. If a widget cannot be found on the host platform, SWT automatically simulates it.

2. The composition of SWT applications

The basic components of an SWT application are the display interface (displays), the command interface (the Shell, the command to enter and initialize the operation), and the Window widget (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.

Figure 1: SWT applications from a variety of perspectives

Figure 1 illustrates the SWT application from a variety of perspectives. The diagram on the left is an inheritance graph 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 appearance of the UI after it is created.

If an application uses more than one thread, each thread uses a display object that is assigned to its own instance. The programmer can use the static method Display.getcurent () to get the current active instance of the display object.

The shell is used to represent windows 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 the child window of display, and it is also a main window. The 2nd class is the dialog shell, which relies on the presence of other shell windows. The shell window eventually becomes the type above, looking at the style bits that are passed to the Shell constructor when the shell is created. The default value for a shell is Dialogshell. That is, if you do not take parameters, the default is a dialog shell. If you give the parameter a display object, the shell will be a high-level shell.

The properties of some window parts must be set at the beginning of their creation. The properties of these window parts are the style bits that are described earlier. In SWT's class, the style bit is defined as a constant. For example, the 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.

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.