Java Reference
In-Depth Information
17.2.3
How about portability? Well, it depends on what “portability” means to you.
If portability means “looks and runs the same on all platforms,” then Swing
offers better portability. If portability means “runs on all platforms for which
there is a Java runtime,” then Swing offers better portability. If portability
means “looks like a native application on all supported platforms,” then SWT
is your choice. Make your selection accordingly.
Portability: Better and Worse
TIP
The bottom line: If you only learn one Java GUI, make it Swing.
17.2.4
The rest of this chapter will be devoted to describing the basic classes of SWT
by converting one of the application classes from the previous chapter from
Swing to SWT. We will not attempt to explain the operating principles of
GUIs. For an introduction to GUI programming, see the previous chapter on
Swing. It introduces the concepts and programming principles for GUI
programming in Java. SWT is functionally similar, although quite spartan,
providing only basic windows, controls, and events.
Eclipse also contains a family of higher level user interface classes, known
collectively as JFace , that provide UI features such as dialogs, wizards, font
handlers, and images. We will not cover JFace in this topic.
The Rest of the Chapter
17.2.5
SWT breaks some of the Java contract. For example, you cannot rely on garbage
collection to clean up SWT objects. Any SWT object you create with new must
be explicitly destroyed with a call to the dispose() method. Why? Since SWT
is implemented with native methods, the low-level implementation allocates
native OS data structures and objects that must be explicitly freed. Since the
Java garbage collector cannot be relied upon to collect objects at a certain time
(or ever, for that matter), these allocations can result in memory leaks and
address space conflicts. As we shall see, however, SWT is well designed to
minimize the amount of this that you need to worry about.
SWT is also close to the metal in the sense that it does not abstract the
underlying message-based event system that drives both X Window and
SWT: Close to the Metal
Search WWH ::




Custom Search