Overview of the Swing API

The Swing package is part of the Java™ Foundation Classes (JFC) in the Java platform. The JFC encompasses a group of features to help people build GUIs; Swing provides all the components from buttons to split panes and tables.

The Swing package was first available as an add-on to JDK 1.1. Prior to the introduction of the Swing package, the Abstract Window Toolkit (AWT) components provided all the UI components in the JDK 1.0 and 1.1 platforms. Although the Java 2 Platform still supports the AWT components, we strongly encourage you to use Swing components instead. You can identify Swing components because their names start with J. The AWT button class, for example, is named Button, whereas the Swing button class is named JButton. In addition, the AWT components are in the java.awt package, whereas the Swing components are in the javax.swing package.

As a rule, programs should not use "heavyweight" AWT components alongside Swing components. Heavyweight components include all the ready-to-use AWT components, such as Menu and ScrollPane, and all components that inherit from the AWT Canvas and Panel classes. When Swing components (and all other "lightweight" components) overlap with heavyweight components, the heavyweight component is always painted on top. [1]

[1] To learn more about the differences between Swing components and AWT components, see the section "Converting to Swing" in the book The JFC Swing Tutorial. This section is also available on this book's CD and online at http://java.sun.com/docs/books/tutorial/uiswing/converting/index.html.

Compiling and Running Swing Programs

To compile and run your Swing programs, we recommend that you either use the latest release of the Java 2 Platform downloaded from http://java.sun.com or use the Java 2 Platform v 1.3 included on this book's CD. You can run Swing applets in any browser that has the appropriate version of Java™ Plug-in installed. [2] Swing applets are covered in Appendix B, Internet-Ready Applets (page 407).

[2] The Java Plug-in is included as part of the JRE 1.3 Win32 release. For more information about the Plugin on other platforms, see http://java.sun.com/products/plugin/index.html

Категории