Examples Index
Lesson: Using Swing Components
Other than
How to Use Tabbed Panes, this section has not yet been updated to reflect features and
conventions of the latest release, JDK 6.0.
This lesson gives you the background information
you need to use the Swing components,
and then describes every Swing component.
It assumes that you've successfully
compiled and run a program that uses Swing components,
and that you're familiar with basic Swing concepts.
These prerequisites are covered in
Getting Started with Swing and
Learning Swing by Example.
This section has pictures of all the standard Swing components,
from top-level containers to scroll panes
to buttons.
To find the section that discusses a particular component,
just click the component's picture.
Describes how to vary the font, color, or other formatting of text
displayed by Swing components
by using HTML tags.
Discusses how to use the features shared by the
JFrame
,
JDialog
, and
JApplet
classes
content panes, menu bars, and root panes.
It also discusses the
containment hierarchy,
which refers to the tree of components
contained by a top-level container.
Tells you about the Swing model architecture.
This variation on Model-View-Controller (MVC)
means that you can, if you wish,
specify how the data and state of a Swing component
are stored and retrieved.
The benefits are the ability to share data and state between components,
and to greatly improve the performance of components
such as tables
that display large amounts of data.
Tells you about the features JComponent
provides to its subclasses
which include almost all Swing components
and gives tips on how to take advantage of these features.
This section ends with API tables
describing the commonly used API
defined by
JComponent
and its superclasses,
Container
and
Component
.
Describes the features and API shared by
all components that descend from
JTextComponent
.
You probably don't need to read this section
if you're just using text fields (formatted or not)
or text areas.
Sections on how to use each Swing component,
in alphabetical order.
We don't expect you to read these sections in order.
Instead,
we recommend reading the relevant "How to" sections
once you're ready to start using Swing components
in your own programs.
For example,
if your program needs a frame, a label, a button, and a color chooser,
you should read
How to Make Frames,
How to Use Labels,
How to Use Buttons, and
How to Use Color Choosers.
Borders are very handy for drawing lines, titles, and empty space
around the edges of components. (You might have noticed that the
examples in this trail use a lot of borders.) This section tells you
how to add a border to any JComponent
.
Many Swing components can display icons. Usually, icons are
implemented as instances of the ImageIcon
class.
This section discusses solutions to common component-related problems.
Try these questions and exercises to test what you've learned in this lesson.