![]() |
Front End GUI: Java Foundation Classes |
||||||
The
Swing component set is a new graphical user-interface (GUI) toolkit that
simplifies and streamlines the development of windowing components -- that
is, the visual components (such as menus, tool bars, dialogs and the like)
that are used in graphically based programs.
With Swing, you can develop lean and efficient GUI components that have precisely the "look and feel" that you specify. For example, a program that uses Swing components can be designed in such a way that it will execute without modification on any kind of computer, and will always look and feel just like a program written specifically for the particular computer on which it is running. When you create such a program and run it under Windows, it has the appearance and behavior of a program written specifically for Windows. When you run the same program on a UNIX workstation, it runs just like any program written for UNIX. When you run it on an Apple Macintosh, it looks and behaves just like any program written specifically for the Mac -- and so on. There are also other ways
to use Swing's PL&F capabilities. For example, Swing comes with a special
cross-platform component set -- currently code-named Metal -- that always
presents the same look and feel (L&F), no matter what operating system
it is running on.
This article introduces the Swing component set and shows how Swing components differ from their pre-Swing AWT predecessors. For a collective look at all the user-interface components in the Swing set, see the "Component Gallery" article. For more details about the classes, interfaces, and methods used in Swing, see the article titled "The Swing Tool Set."
Swing architecture The Swing toolkit ushers in a new area of graphical user interface (GUI) programming because it is the first GUI toolkit that lets developers create lightweight components with a pluggable look-and-feel design. Swing components are said to be lightweight because they don't rely on user-interface code that's native to whatever operating system they're running on. Consequently, they can usually be implemented using only about half the classes that earlier "heavyweight" components require. Because many "heavyweight" components are used in programs that were written before Swing was introduced, the creators of Swing have made it possible to mix heavyweight and lightweight components in the same program. To learn how to do that, see the article titled "Mixing Heavy and Light Components". (For more information about peer code, lightweight components, and components in general, see the latest editions of The Java Tutorial.) Swing and AWT From an architectural standpoint, the Swing component set extends -- but does not replace -- the Abstract Windowing Toolkit (AWT) that is familiar to users of the the Java programming language. AWT, like Swing, is a set of object-oriented classes designed to help programmers write graphical user interfaces, or GUIs, for their Java programs. Swing components are lightweight, just like the AWT components that made their debut along with the release of JDK 1.1. But the Swing set contains far more components than the pre-Swing AWT toolkit did, and Swing components have many new features and capabilities that old-style AWT components did not have. For example, all Swing UI components are designed using the pluggable look-and-feel (PL&F) architecture described at the beginning of this article. You can learn about many other new features of Swing components reading The Swing Connection. By offering all these new features, Swing significantly extends and expands the power and versatility of the pre-Swing AWT toolkit. More specifically, Swing extends the Lightweight UI Framework that became part of the Java AWT with the introduction of JDK 1.1. |