AWT, Swing or SWT:
Which one? - 2020
Why is there more than one
Java GUI tool kit?
Because there is none
that fits all.
1. Abstract Window Toolkit (AWT)
The Abstract Window Toolkit (AWT) is Java's original
platform-independent user-interface widget
toolkit.
The AWT is now part of the Java Foundation Classes (JFC)
— the standard API for providing a graphical user interface (GUI)
for a Java program.
AWT is also the GUI toolkit for a number of Java ME profiles.
AWT's main advantages are that it comes standard with every version of
Java technology, including Java implementations in old Web browsers,
and it is very stable. This means you do not need to install it, you
can depend on it being available everywhere you find a Java runtime
environment, and it will have the features you expect.
AWT is a very simple tool kit with limited GUI components, layout
managers, and events.
This is
because Sun Microsystems decided to use a lowest-common denominator
(LCD) approach for AWT.
Only GUI components defined for all Java host
environments would be used.
As a result, some
commonly used components, such as Tables, Trees, Progress Bars, and
others, are not supported.
For applications that need more component
types, you need to create them from scratch.
This is a big burden.
Swing is a widget toolkit for Java. It is part of Sun Microsystems'
Java Foundation Classes (JFC) — an API for providing a graphical
user interface (GUI) for Java programs.
Swing was developed to provide a more sophisticated set of GUI
components than the earlier Abstract Window Toolkit (AWT). Swing provides a
native look and feel that emulates the look and feel of several
platforms, and also supports a pluggable look and feel that allows
applications to have a look and feel unrelated to the underlying
platform.
Swing is built on parts of AWT. All Swing parts are also AWT parts.
Swing uses the AWT event model and support classes, such as Colors,
Images, and Graphics.
The Swing components, layout managers, and events.
Swing may not be able to take advantage of hardware GUI accelerators
and special host GUI operations.
As a result, Swing applications may be
slower than native GUIs.
Sun has worked hard on the performance of the
recent versions of Swing (Java V1.4 and 1.5),
and this disadvantage is
becoming less noticeable.
Because Swing's design is more robust, its
code base is larger.
This can mean it takes a beefier machine to run it than AWT or SWT
might.
3. Standard Widget Toolkit (SWT)
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 Java GUI toolkits provided by
Sun Microsystems as part of the Java Platform,
Standard Edition.
SWT is a low-level GUI tool kit comparable in concept to AWT
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.
JFace is a set of enhanced components and utility services to make
building GUIs with SWT easier.
The builders of SWT learned from the AWT and Swing implementations and
tried to build a system
that had the advantages of both without their
disadvantages. In many ways, they succeeded.
SWT is a lot like AWT in that it is based on a peer implementation.
It overcomes the LCD problem faced by AWT by defining a set of controls
adequate to make most office applications
or developer tools and then,
on a host-by-host basis, creating emulated (like Swing) controls for
any not supplied
by the particular host.
For most modern hosts, nearly all the controls are based on native
peers.
This means that an SWT-based GUI has a host look and feel, and
host performance.
This avoids the most widely held complaints with AWT and Swing.
Certain
hosts have low-function controls, so SWT supplies extended, often
emulated,
versions (often with "C" as the first letter in their names)
to allow the more generally expected behavior.
SWT is different from AWT in how the peers work.
In SWT, the peers are
just wrappers on host controls.
In AWT, peers can provide services to minimize the differences between
hosts
(this is where AWT ran into a lot of its behavior issues).
This
means that an SWT application is really a host application, with all
the good and bad points that entails.
So, we can say that SWT does a remarkable job of creating a
portable solution, albeit not as well as Swing.