Java Reference
In-Depth Information
Look-and-Feel Observation 12.5
Swing GUI components allow you to specify a uniform look-and-feel for your application
across all platforms or to use each platform's custom look-and-feel. An application can
even change the look-and-feel during execution to enable users to choose their own pre-
ferred look-and-feel.
Lightweight vs. Heavyweight GUI Components
Most Swing components are lightweight components —they're written, manipulated and
displayed completely in Java. AWT components are heavyweight components , because
they rely on the local platform's windowing system to determine their functionality and
their look-and-feel. Several Swing components are heavyweight components.
Superclasses of Swing's Lightweight GUI Components
The UML class diagram of Fig. 12.5 shows an inheritance hierarchy of classes from which
lightweight Swing components inherit their common attributes and behaviors.
Object
Component
Container
JComponent
Fig. 12.5 | Common superclasses of the lightweight Swing components.
Class Component (package java.awt ) is a superclass that declares the common features
of GUI components in packages java.awt and javax.swing . Any object that is a Con-
tainer (package java.awt ) can be used to organize Component s by attaching the Compo-
nent s to the Container . Container s can be placed in other Container s to organize a GUI.
Class JComponent (package javax.swing ) is a subclass of Container . JComponent is
the superclass of all lightweight Swing components and declares their common attributes
and behaviors. Because JComponent is a subclass of Container , all lightweight Swing com-
ponents are also Container s. Some common features supported by JComponent include:
1. A pluggable look-and-feel for customizing the appearance of components (e.g.,
for use on particular platforms). You'll see an example of this in Section 22.6.
2. Shortcut keys (called mnemonics ) for direct access to GUI components through
the keyboard. You'll see an example of this in Section 22.4.
3. Brief descriptions of a GUI component's purpose (called tool tips ) that are dis-
played when the mouse cursor is positioned over the component for a short time.
You'll see an example of this in the next section.
4. Support for accessibility , such as braille screen readers for the visually impaired.
5. Support for user-interface localization —that is, customizing the user interface to
display in different languages and use local cultural conventions.
 
Search WWH ::




Custom Search