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

Trail: Creating a GUI with JFC/Swing

Lesson: Swing Features and Concepts

This lesson introduces Swing's features and explains all the concepts you need to be able to use Swing components effectively. At the end of this lesson we dissect a Swing program, as a means of reviewing everything you've learned.

Swing Components and the Containment Hierarchy

Swing provides many standard GUI components such as buttons, lists, menus, and text areas, which you combine to create your program's GUI. It also includes containers such as windows and tool bars.

Layout Management

Containers use layout managers to determine the size and position of the components they contain. Borders affect the layout of Swing GUIs by making Swing components larger. You can also use invisible components to affect layout.

Event Handling

Event handling is how programs respond to external events, such as the user pressing a mouse button. Swing programs perform all their painting and event handling in the event-dispatching thread.

Painting

Painting means drawing the component on-screen. Although it's easy to customize a component's painting, most programs don't do anything more complicated than customizing a component's border.

Threads and Swing

If you do something to a visible component that might depend on or affect its state, then you need to do it from the event-dispatching thread. This isn't an issue for many simple programs, which generally refer to components only in event-handling code. However, other programs need to use the invokeLater method to execute component-related calls in the event-dispatching thread.

More Swing Features and Concepts

Swing offers many features, many of which rely on support provided by the JComponent class. Some of the interesting features this lesson hasn't discussed yet include support for icons, actions, Pluggable Look & Feel technology, assistive technologies, and separate models.

The Anatomy of a Swing-Based Program

A sample Swing application named Converter shows how Swing programs work and how the code hangs together.

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

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