The JavaTM Tutorial
Previous Page Lesson Contents Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Creating a GUI with JFC/Swing
Lesson: Getting Started with Swing

Swing Package Names

The names of the Swing packages have varied over time. This trail uses the final Swing package names, which generally start with javax.swing. If you have code that uses earlier package names, such as com.sun.java.swing, then you will need to convert it.

This section has two parts:

How to Convert to the Final Package Names

Between the Beta 2 and Beta 3 releases of Swing 1.1, the names of the Swing packages changed. In Swing 1.1 Beta 2, for example, the main Swing package was called com.sun.java.swing, while in Swing 1.1 Beta 3, the name is javax.swing. The same changes occurred between the Beta 4 and RC1 releases of the Java 2 Platform, v 1.2.

Converting the package names is easy, although it can be tedious to do by hand when many source files are involved. Fortunately, the Swing team provides a utility called PackageRenamer that converts programs to use the final Swing package names. You can find the program at http://java.sun.com/products/jfc/PackageRenamer(outside of the tutorial) .

The following table shows how the names have changed:

Old Name
(Swing 1.1 Beta 2, Java 2 Platform v 1.2 Beta 4)
New, Final Name
(Swing 1.1 [Beta 3 and later], Java 2 Platform v 1.2 RC1)
com.sun.java.accessibility javax.accessibility
com.sun.java.swing javax.swing
com.sun.java.swing.border javax.swing.border
com.sun.java.swing.colorchooser javax.swing.colorchooser
com.sun.java.swing.event javax.swing.event
com.sun.java.swing.filechooser javax.swing.filechooser
com.sun.java.swing.plaf javax.swing.plaf
com.sun.java.swing.plaf.basic javax.swing.plaf.basic
com.sun.java.swing.plaf.metal javax.swing.plaf.metal
com.sun.java.swing.plaf.motif com.sun.java.swing.plaf.motif (no change)
com.sun.java.swing.plaf.multi javax.swing.plaf.multi
com.sun.java.swing.plaf.windows com.sun.java.swing.plaf.windows (no change)
com.sun.java.swing.table javax.swing.table
com.sun.java.swing.text javax.swing.text
com.sun.java.swing.text.html javax.swing.text.html
com.sun.java.swing.tree javax.swing.tree
com.sun.java.swing.undo javax.swing.undo
com.sun.java.swing.plaf.mac com.sun.java.swing.plaf.mac (no change)
com.sun.java.accessibility.util com.sun.java.accessibility.util (no change)


Note: The com.sun.java.accessibility.util package isn't part of the JFC 1.1 release or Java 2 Platform. It's distributed separately as part of the Accessibility Utilities(outside of the tutorial).

The com.sun.java.swing.plaf.mac package is distributed only in the Macintosh download of JFC 1.1(outside of the tutorial) and the Mac OS Runtime for Java(outside of the tutorial), also known as MRJ.


The History of the Swing Package Names

At various times, the Swing API has used the following package names:

In the end, the core Swing API is under the javax.swing package, with some additional Sun-provided packages under com.sun.java.swing. The previous table gives details of the final package names. Now let's look at how the names have varied over time.

In all the JFC 1.1 releases up through Swing 1.1 Beta 2, the name of the main Swing package was com.sun.java.swing. The JFC 1.1 releases were meant to be used with JDK 1.1. There was no built-in support for Swing until the 1.2 Beta 2 version of the Java 2 Platform.

In the Beta 2 and Beta 3 releases of the Java 2 Platform v 1.2, the Swing API was in a new package: java.awt.swing. However, some of our customers told us that they wanted the Swing package names to be the same in JFC 1.1 and the Java 2 Platform, so that they would be able to use the exact same code for both releases.

As a result, in v 1.2 Beta 4 the Swing team moved the main Swing package to com.sun.java.swing. Unfortunately, many people didn't like this change. One of the reasons for the discontent was that having a core API in a package that didn't begin with "java" seemed to imply that Swing wasn't a core API.

The Swing team reacted by floating a proposal(outside of the tutorial) to move the Swing packages to javax.swing in both JFC 1.1 and the Java 2 Platform. The proposal was favorably greeted by the user community, and the new package names were introduced in Swing 1.1 Beta 3 and the Java 2 SDK v 1.2 RC1. The right column of the preceding table shows the final package names.


Previous Page Lesson Contents Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved.