Brought to you by EarthWeb
ITKnowledge Logo Login Graphic Click Here!
Click Here!
ITKnowledge
Find:
 
EXPERT SEARCH ----- nav

EarthWeb Direct

EarthWeb Direct

EarthWeb sites: other sites

Previous Table of Contents Next


Packages

The Swing component toolkit consists of over 250 pure Java classes and 75 interfaces contained in more than 10 packages. They are used to build lightweight user interfaces. Swing consists of non–user-interface (non-UI) classes as well as the more familiar user-interface (UI) classes. The non-UI classes provide services and other operations for the UI classes. They do not display anything on screen. Examples of non-UI Swing classes are the events fired by Swing components and the Swing data model classes. The UI classes, such as buttons and labels, create visible components that applications can display on screen, and they can be combined to create a complete graphical user interface. The Swing UI components descend from the JComponent class, and all begin with the capital letter J.

Swing packages that are typically used by developers when building GUIs are listed, and briefly explained, in the following sections.

Where should the Swing packages live?

As was mentioned earlier in the chapter, Swing was released to developers for feedback during design and development of the toolkit. There were two versions of the toolkit for review: one that ran with the released 1.1 version of the JDK, and another that ran with the 1.2 beta version of the JDK. The root of the toolkit for the 1.1 JDK was contained in the com.sun.java.swing package. Support classes were located in sub-packages to this base package. The root of the toolkit for the 1.2 beta JDK was java.awt.swing. Due to security restrictions browsers can not download from the network core Java classes, that is, classes whose package name begins with java. The com.sun.java.swing package name allowed 1.1-enabled browsers to download the Swing packages from the server.

When the 1.2 beta4 version of the JDK was released, it was also announced that the Swing packages were not to be part of the java.awt.swing package, but would remain in the 1.1 JDK-compatible com.sun.java.swing package. In JDK Release Candidate 1, the package name changed to javax.swing. The rational for this decision was that many developers had developed applications using the 1.1 names, and changing to the 1.2 package name would be complicated. This decision has been very controversial. Until this point, classes contained in com.sun packages have been undocumented and not guaranteed to be available on all platforms. Developers have raised the concern that the Swing packages will not be available on all platforms. However, JavaSoft has guaranteed that Swing is part of the core Java release and will be available on all platforms, including browsers.

This author agrees with the concerns expressed by many developers after the package name announcement. The core Java packages should follow a consistent naming convention. The reason cited for not changing the name is insufficient. Changing package names for the Swing packages in a large project would have been painful; however, this would have been a one-time change, and developers were told of the intention to change the package names from the beginning. Now developers are going to have to live with the pain of a non-standard named package for the foreseeable future.

The Swing Package: javax.swing

This is the largest of the Swing packages consisting of approximately 100 classes and 25 interfaces. The majority of the UI classes (the “J” classes) are contained in this package. The exceptions are JTableHeader, implemented in the javax.swing.table package, and JTextComponent, implemented in the javax.swing.text package. Both of these packages are described shortly. Also contained in this package are high-level choice components. This type of component allows the user to visually choose a value from a fixed set of possible values—choosing a color, for example. The components in this package are the primary focus of this book (see Figure 1.2). Examples of their use are given throughout.


Figure 1.2  Examples of the basic Swing components in the Windows PL&F.

The Basic Package: javax.swing.plaf.basic

The Basic package contains classes that define the default look-and-feel of Swing components. By extending these classes, components with a customized PL&F can be developed. This is the second largest package in terms of the number of classes, containing approximately 40 classes. The high number of classes should give a feel for the amount of work required to develop a complete PL&F.

The Border Package: javax.swing.border

The Border package contains the Border interface and nine classes that implement this interface. Typically classes in this package are not instantiated directly; instead, instances are obtained via methods in the BorderFactory class contained in the javax.swing package. However, the constants defined in the classes in this package are often used when obtaining borders from the factory. Classes in this package can be extended to create a specialized border. The Border package and the borders contained in the JFC are presented in Chapter 5, “Basic Components.”

The Event Package: javax.swing.event

The Event package defines events specific to Swing components. The events defined in this package fill roles similar to those defined in the java.awt.event package. There are approximately 25 Swing-specific events. The events themselves and their associated Listener interfaces are defined in this package. Swing events are used by the various data models contained in the JFC. The events are presented with the classes that fire the particular event.

The Multipackage: javax.swing.plaf.multi

The Multipackage consists of multiplexing UI classes. These allow Swing components to have UIs provided by multiple user-interface factories.

The Pluggable Look-and-Feel Package: javax.swing.plaf

The PL&F package consists of classes that provide Swing components with pluggable look-and-feel capabilities. If a custom PL&F is being developed and the classes in the javax.swing.plaf.basic package cannot be extended, the abstract classes contained in this package can be used as a starting point. The JFC is shipped with three PL&Fs: the Windows PL&F contained in the com.sun.java.swing.plaf.windows package (see Figure 1.2), the Motif PL&F contained in the com.sun.java.swing.plaf.motif package (see Figure 1.3), and the Metal platform-neutral PL&F contained in the javax.swing.plaf.metal package (see Figure 1.4). The Macintosh PL&F contained in the com.sun.java.swing.plaf.mac package is available separately.


Figure 1.3  The Motif PL&F.


Figure 1.4  The Metal PL&F.


Previous Table of Contents Next
HomeAbout UsSearchSubscribeAdvertising InfoContact UsFAQs
Use of this site is subject to certain Terms & Conditions.
Copyright (c) 1996-1999 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.