Java Swings/Overview

Swing is a tool kit in Java which provides a way to build cross platform user interfaces. It is built on top of and designed as a replacement for AWT, the other UI toolkit built into Java. SWT is a third toolkit you may hear about. SWT is an open source toolkit and is a full topic in of itself, see SWT's Homepage for more information.

Overview
Swing provides many controls and widgets to build user interfaces with. Swing class names typically begin with a J such as,  ,. This is mainly to differentiate them from their AWT counterparts and in general are one-to-one replacements. Swing is built on the concept of Lightweight components vs AWT and SWT's concept of Heavyweight components. The difference between the two is that the Lightweight components are rendered (drawn) using purely Java code, such as drawLine and drawImage, whereas Heavyweight components use the native operating system to render the components.

Some components in Swing are actually heavyweight components. The top-level classes and any derived from them are heavyweight as they extend the AWT versions. This is needed because at the root of the UI, the parent windows need to be provided by the OS. These top-level classes include,  ,   and. All Swing components to be rendered to the screen must be able to trace their way to a root window or one of those classes.

So what does using Swing get you? So far we've only talked about components and rendering. Well, to start with you get the following.
 * Controls: Buttons, Check Boxes, Lists, Trees, Tables, Combo boxes (dropdown list), Menus, Text fields
 * Displays: Labels, Progress bars, Icons, Tool Tips
 * Pluggable look and feels (PLAFs): Windows, CDE/Motif, Mac. Allows for "skinning" the application without changing any code


 * Standard Top-Level Windows: Windows, Frames, Dialogs etc.
 * Event Listener APIs
 * Key bindings & mnemonics: Allow keystrokes to map to specific actions.