• The look and feel of a Swing application are not exactly the same as those of a native
application. The developers of Swing keep trying to reproduce the look and feel of systems
like Windows, but they can't stay synchronized with new OS versions. Furthermore, the
customization of the colors and font schemes of the underlying windowing system are
difficult to propagate in the emulated widgets.
SWT and JFace
SWT (the Standard Widget Toolkit) is an alternative toolkit that was created by IBM and has
become popular due to its use in the Eclipse platform. SWT has now been donated to the
open source community along with the rest of the Eclipse platform.
SWT was created to solve the problems existing in AWT (lack of functionality) and Swing
(inconsistency with the native look and feel, and poor performance). This has been achieved
by using a solution that lies between the two extreme approaches represented by AWT
(using the smallest set of common features) and Swing (emulating everything). Like Swing,
SWT provides a rich collection of widgets with all the functionality required by a modern UI --
but like AWT, SWT also makes use of the native widgets and libraries of the underlying
platform.
The collection of widgets provided by SWT includes all the components a UI programmer
might need to build a modern user interface: trees, tables, progress indicators, sliders,
tabbed panes, and so on. Although the internal implementation makes use of a proprietary
API on each platform, the public API, against which a UI developer will program, is
completely OS-independent and quite simple to use -- like AWT.
The reason why SWT can offer much more functionality than AWT is that it uses native
widgets where possible, but emulates widgets that may not be available on a specific
platform, just like Swing does for all widgets. For example, Motif doesn't provide any tree
component, but Windows and GTK do. The implementations of the tree widget under
Windows and GTK simply make use of the native widgets. The Motif implementation
emulates a tree by combining several simpler widgets. The programmer using SWT doesn't
notice the difference, because the public API is the same for all platforms. The emulated
widget under Motif may not perform as well as a native widget would, but this performance
issue would only concern this particular widget on this particular platform.
SWT is a standalone library. It doesn't make use of any AWT classes, and has no
dependency on Eclipse itself. Thus, you can see SWT as an alternative to AWT or Swing.
The advantages are obvious:
• Because, for the most part, it uses native components, SWT preforms much better than
Swing.
• With SWT, you get a better integration with the underlying windowing system. The look
and feel are that of the underlying system, and the color and font schemes of the system
are used. A Java application using SWT cannot be distinguished from a native application.
• SWT has already been ported to most of the platforms on the market, so platform port is
not an issue.
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Migrate your Swing application to SWT Page 5 of 96
评论2
最新资源