Standard Widget Toolkit


The Standard Widget Toolkit (SWT) is a graphical widget toolkit for use with the Java platform. It was originally developed by IBM and is now maintained by the Eclipse Foundation in tandem with the Eclipse IDE. It is an alternative to the AWT and Swing JavaGUI toolkits provided by Sun Microsystems as part of the Java Platform, Standard Edition.
SWT is written in Java. To display GUI elements, the SWT implementation accesses the native GUI libraries of the operating system using JNI (Java Native Interface) in a manner that is similar to those programs written using operating system-specific APIs. Programs that call SWT are portable, but the implementation of the toolkit, despite the fact that part of it is written in Java, is unique for each platform.

SWT is the UI library used by Eclipse. SWT provides the some rich UI components on several platforms. The native widgets of the OS are accessed by the SWT framework via JNI. If a widget is not available on a certain platform, SWT emulates the unavailable widget. SWT is from design similar to AWT but AWT does not provide widgets if they are available on all platform, therefore the AWT widget library is very small. SWT does provide a API which is very close to the native API, higher abstraction API is provided by JFace .
The key components of SWT applications are the classes "org.eclipse.swt.widgets.Display" and "org.eclipse.swt.widgets.Shell". A Shell represents a window. Displays are responsible from managing event loops, controlling communication between the UI thread and other threads and managing fonts and colors. The Display is the basic for all SWT capabilities and can be seen as the model for SWT. Every SWT application requires at least one Display and one or more Shell instances. The main shell gets as a default parameter a Display as constructor argument.
SWT widgets are contained in the packages "org.eclipse.swt.widgets" and "org.eclipse.swt.custom". While SWT tries to use native widgets as much as possible it is not possible to fulfill all requirements with the native widgets. Therefore some widgets extends the native platform. These are part of the "org.eclipse.swt.custom" package and usually start with an addition C to indicate that their are custom widgets, e.g. CCombo. CCombo provides compared to Combo the possibility to set the height of the widget. Another example is StyledText a class which provides lots of possibilities for displaying text.
Widgets from the package "org.eclipse.swt.custom" are implemented in pure Java while widgets from "org.eclipse.swt.widgets" are using native code. Custom widgets are also not supposed to use the internal classes of SWT as these classes may be different on different platforms. Every custom widget must inherent from "Composite" or "Canvas" as only for these classes API compliance is sure. If the new custom widget is supposed to contain other widgets it should extend Composite otherwise Canvas.
To delete a SWT widget you have to call the method dispose. SWT also does not provides it own event loop, the programmer has to explicitly start and check the event loop.

Comments

Popular posts from this blog

input stream or file to X509Certificate

How to rebase chain of git changes on master ?