Java Reference
In-Depth Information
completely platform independent, so these widgets are referred to as being “lightweight.” The
notions of heavyweight and lightweight in this case indicate how the GUI components are imple-
mented, rather than how they look or how complex they are.
Note In fact, not all Swing components are lightweight—there a few notable
exceptions, but more on that later.
One important aspect to keep in mind is that Swing is implemented, for the most part, as an extension
of AWT. That is, every Swing top‐level component (don't worry about what top‐level means, you'll
encounter this again in more detail soon) is implemented as a class extending an AWT counterpart,
the difference being that the Swing components extend the AWT set in such a way that no native
calls to the operating system are made anymore.
Since Swing draws the components itself (instead of relying on the operating system), it makes sense
that there is some common set of functionality to draw basic 2D primitives (rectangles, lines, text, cir-
cles, and so on) on-screen. Indeed, this core functionality is provided by another set of libraries called
“Java 2D,” which, confusingly, is located under the java.awt package (the reason for this is that AWT
already contained some form of basic graphic functionality, which was thus also extended).
Standard Widget toolkit (SWt)
When people build GUIs in Java, they'll still almost always be using Swing to do so. Therefore, in
this chapter, you'll focus most on this library. That said, however, there exists a number of addi-
tional GUI libraries as well, with the Standard Widget Toolkit (SWT) as a notable first example.
The origins of SWT date all the way back from when AWT was still in its infancy (and Swing still
under development). The developers at IBM decided that AWT was too buggy and developed their
own alternative, SWT. It is similar to AWT in the sense that its components are also heavyweight
and thus also call native operating system routines to draw and display GUI components. However,
SWT also offers some additional widgets using native code, in cases where native-platform GUI rou-
tines do not support the functionality required for SWT. In that way, SWT is a compromise between
native performance and Swing's ease of use of.
It is interesting to note that SWT was originally conceived to support the development of VisualAge,
an IDE made by IBM at the time. The company decided to eventually open‐source the project,
which then led to the development of Eclipse. That means Eclipse itself—the IDE used in this
book—can be regarded as a prime example of SWT in action.
Does it make sense to use it yourself? In some cases, it might. When you are looking for a GUI tool-
kit that provides a sensible programming interface to access native widgets in a functional manner
and with a more sensible structure and fallbacks than AWT, it might be interesting to give SWT a
shot. If you care more about customization support and ease of use, and want a look and feel that
appears similar on all platforms, Swing is probably better suited.
JavaFX
JavaFX is the “new kid” on the block concerning GUI toolkits, even though it has been around for
quite some time by now. Its original goal was to offer a software platform for creating rich Internet
 
Search WWH ::




Custom Search