Java Reference
In-Depth Information
Ocean Look and Feel is the default value for Java applications and applets.
Motif is an alternate Look and Feel supplied with the Java SDK. Windows Look
and Feel uses Windows operating system properties and appearance settings to
design its interface. GTK stands for GIMP Tool Kit, which is a set of graphics and
images used to create application programs in UNIX-based systems. GIMP is an
acronym for the GNU Image Manipulation Program — a graphics editing pro-
gram originally designed for Linux.
Programmers are not limited to the Look and Feels supplied with the Java
platform, however. You can use any Look and Feel located in your program's
class path. External Look and Feels usually are provided in one or more JAR files
that you add to your program's class path at run time. JAR files are archive files
created with the Java Archive tool that comes with Java SDK. Archive files are
compressed files similar to zipped files. Typically, a JAR file contains the class
files and auxiliary resources associated with applets and applications. Many free
Look and Feel downloads are available via the Web. Once an external Look and
Feel is in the program's class path, the program can use it in the same way it
would use any of the Look and Feels shipped with the Java platform.
J ava 2
J ava 2
v 5 . 0
JAVA UPDATE
v 5 . 0
One of the most
noticeable changes
implemented in J2SE
version 5.0 is in the
look and feel of appli-
cations. If you use the
Java look and feel, your
application will auto-
matically get the new
default setting, called
Ocean. Ocean was
designed with compati-
bility in mind so the
size of GUI components
did not change. Ocean
is a derivative of the
Metal theme; therefore,
the code in Table 8-4
that references the
Metal look and feel will
generate the new
Ocean settings. If you
have created a custom
look and feel, your
application will look the
same as it did in previ-
ous versions of Java.
Using External Look and Feels
External Look and Feels usually are provided in one or more JAR
files that you add to your program's class path at run time. Look
and Feels may be created by other programmers or downloaded
from the Web.
The UIManager Class
Setting the Look and Feel should be the very first step for programs that use it.
Otherwise, Java will initialize the Look and Feel regardless of the code. The reason
for this is because when a static field references a Swing class, it causes the Look
and Feel to be loaded. When a program does not set its Look and Feel, the Swing
UIManager is required to determine which Look and Feel to use. The UIManager
class keeps track of the current Look and Feel and its defaults. Java manages three
levels of defaults: user defaults, Look and Feel defaults, and system defaults. A call to
UIManager.get(), however, checks all three levels in sequence and returns the first
non-null value. A call to UIManager.put() affects only the user defaults. A call to the
setLookAndFeel() method does not affect the user defaults but merely replaces the
middle defaults level. Table 8-4 displays some of the available methods from the
UIManager class.
First, the UIManager checks whether the programmer has specified a pre-
ferred Look and Feel through the operating system. If the user has specified a
Look and Feel, the UIManager attempts to use it. If the user has not, or if the
user's choice is not valid, the UIManager chooses the Java Look and Feel.
If you are using Java
5.0 and wish to view
the BillPayer program
with the new Ocean
Look and Feel rather
than the Motif Look
and Feel, replace line
22 on page 496 with
the following code:
22 UIManager.setLookAndFeel ( "javax.swing.plaf.metal.MetalLookAndFeel" ) ;
Search WWH ::




Custom Search