Previous | Next | Trail Map | Creating a User Interface | Contents

Using the JFC/Swing Packages

The Java Foundation Classes (JFC) include many ready-to-use components, nicknamed Swing components. This lesson tells you how to use the Swing 1.1 Beta(in the API reference documentation) components, which are provided in the JFC 1.1 (Swing 1.1 Beta) release and the JDK 1.2 Beta 4 release. With a few exceptions that we note, our code is compatible with Swing 1.0.3(in the API reference documentation).

This is a work in progress! Please help us improve this lesson by sending comments and suggestions to tutorial@java.sun.com, putting the word "swing" in the subject. Keep an eye on this section of the tutorial and The Swing Connection for the latest information on the Swing project.

This lesson was last updated August 14, 1998, to add a new color chooser example and more information about text features. The new text information is in the text field and text component pages, as well as in new pages on caret, document, and undoable edit listeners. On August 3, we added new information on Swing 1.1 Beta and improved the coverage of most components, especially dialogs, lists, menus, panels, root panes, scroll panes, split panes, tabbed panes, tables, text components, text fields, list selection listeners, borders, box layout, We also improved many examples. If you've already downloaded the tutorial, you can update your copy of this lesson; see Download The Java Tutorial.

This Swing lesson, together with a Swing version of the rest of the UI trail, will soon be published by Addison-Wesley as The JFC Swing Components: A Tutorial Guide to Constructing GUIs. To everyone who sent e-mail helping us determine the scope of the book: Thanks!


Getting Started with Swing

To write programs using the Swing components, you must first download the appropriate JDK and JFC releases. Then you can compile and run the "Hello Swing" application that we provide. Next, take a tour of the "Hello Swing" program to learn how a Swing program works.

Overview of the Swing Components

This section shows you each Swing component and then links to where you'll learn how to use the component. Here's a preview of what you'll see:

Using Each Swing Component

The Swing components conform to the Swing architecture, which means that they are lightweight, have a pluggable look and feel, conform to the requirements of JavaBeans, and so on. Despite the plethora of features, the components are easy to use.

This section first gives you an overview of code that you might use when using any Swing component. Then each component has a subsection that tells you all about using that component.

Using the Common Swing Events

Swing defines a few event types to supplement the AWT events. This section tells you about the most commonly used Swing events.

Using Other Swing Features

This section tells you how to use Swing features such as actions, borders, box layout, icons, and timers. It also covers topics such as using threads in Swing programs.

Writing Lightweight Components Using the Swing Release

This section will tell you how to write simple components, using subclasses of Swing components. (It's easy!) For now, you can look at two examples. The first is a ruler used as a header in the scroll pane example: Rule.java The second is a custom button in the Bingo example: NumberButton.


Previous | Next | Trail Map | Creating a User Interface | Using the JFC/Swing Packages