Note: An updated and expanded version of this
material appears in
Core Web Programming 2nd Edition. All source code (plus
sample chapters) is available at
1. Main New Features
Not built on native window-system windows.
- Much bigger set of built-in controls.
Trees, image buttons, tabbed panes, sliders,
toolbars, color choosers, tables, text areas to display HTML or RTF,
- Much more customizable.
Can change border, text alignment, or add image to almost any
control. Can customize how minor features are drawn. Can
separate internal representation from visual appearance.
- "Pluggable" look and feel.
Can change look and feel at runtime, or design own look and feel.
- Many miscellaneous new features.
Double-buffering built in, tool tips, dockable tool bars,
keyboard accelerators, custom cursors, etc.
2. Swing is Standard in Java 2 (aka Java 1.2)
- Includes Java2D (see
- Adds support for MIDI, WAV, and other audio.
3. Separate Swing package can be added to Java 1.1.
- Does not include Java2D or new audio formats.
- Download it
4. Getting More Info.
on-line Java 2 API or the books in the Swing/JFC section of
5. Components are named JXxx.
E.g. JFrame, JPanel, JApplet, JDialog, JButton, etc.
6. There is an almost-equivalent Swing component for most AWT
7. Do drawing in paintComponent, not paint.
8. Instead of adding components directly to frames or applets, use the
- Add to content pane via
- Replace content pane via
9. Model-View-Controller architecture lets you change the internal
data representation for lists, trees, tables, etc.
10. Swing was in the com.sun.java.swing package in beta releases of
1.2. Switched to javax.swing in 1.2 final.
11. Default "look and feel" is a Java-specific one.
- Need special call to get native look
- Default called "Java look & feel" (formerly
12. Mixing AWT and Swing is doomed.
AWT components are always on top, and z-ordering problems catch you in
many unexpected ways. Stick with the AWT or move completely to
This page is part of my
Quick Swing Tutorial for AWT Programmers. © 1999
Marty Hall. All
source code freely available for unrestricted use. Created for for
work in the Research
and Technology Development Center of the Johns Hopkins University
Applied Physics Lab, for courses in the Johns Hopkins Part-Time MS
Program in Computer Science, and for various industry seminars and
Java short courses.