Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Making the Forum Swing, Part 1

Find out how to develop and deploy a commercial-quality GUI with Swing

  • Print
  • Feedback
In previous versions of Java, the Abstract Windowing Toolkit (AWT) provided the basis for GUI development using Java.

The AWT has taken a lot of heat for its shortcomings, which included lack of decent widgets, a weird 1.0 event model, inconsistent behavior across platforms, and large functionality deficiencies.

These problems have been addressed in Java's 1.2 release through the inclusion of the Java Foundation Classes (JFC). The JFC contains much additional feature support, including a new set of GUI widgets and support classes called Swing.

Note: To develop with Swing and Java 1.2 and deploy your apps on the Internet/intranet, you'll need to download and install JDK 1.2 and Java Plug-in. See the sidebar "Tips for installing JDK 1.2 Beta 4 and the Java Plug-in" for details.

Intro to JFC

The JFC provides the new core Java reference platform for Java GUI and client-side development. JFC contains the following components:

  • Swing API: New classes and interfaces for building GUIs

  • Accessibility API: Interface support features for the disabled

  • 2D API: True 2D graphics support

  • Pluggable Look and Feel: Ability to define a particular look and feel and change application look and feel on the fly

  • Printing and Drag and Drop APIs: Printing and inter-application desktop drag-and-drop capabilities


The Swing portion of JFC is really all we're interested in for rebuilding the Forum.

Spring into Swing

Swing is the crown jewel of the JFC. It is, in essence, the "new AWT," and as such it supercedes the old AWT (although support for the old AWT is supported in Java 1.2 for backwards compatibility).

This portion of the Swing hierarchy is analogous to the AWT hierarchy



The architecture of Swing components is loosely based on the Model-View-Controller (MVC) design pattern. MVC separates an entity that needs to present data into three parts -- the model, the view, and the controller. This responsibility split allows a component's rendering to be decoupled from its data and event handling.

Swing classes and interfaces come in two varieties: user interface (UI) classes, such as widgets, and non-UI classes, such as event classes and utility classes for widgets.

The com.sun.java.swing package and the Swing components
The com.sun.java.swing package is the main Swing package. It contains all the Swing widgets and components and most of their supporting classes.

These are the additional new components that Swing has to offer



Swing's components form a new class hierarchy parallel to the original AWT. The root of this hierarchy is JComponent. Swing's UI classes are based on the lightweight component facility introduced in Java 1.1. Lightweight components are pure Java, and therefore have no native peers.

All Swing components have the following characteristics, among others:

  • They are beans
  • They are lightweight
  • Their borders may be changed
  • They support flicker elimination (so you don't have to)


The purpose of most of the Swing components can be inferred by their names. Some of the more interesting widget types include:

  • Print
  • Feedback

Resources
  • Download the complete source as a zip file http://www.javaworld.com/jw-09-1998/step/jw-09-step.zip
  • Download the complete source as a gzipped tar file http://www.javaworld.com/jw-09-1998/step/jw-09-step.tar.gz
  • Read the other Step by Step articles by Shoffner and Hughes http://www.javaworld.com/topicalindex/jw-ti-step.html
  • Thinking about buying a book on JFC and Swing technologies? Don't make a move until you read Laurence Vanhelsuwé's detailed review on the available books covering this craze http://www.javaworld.com/jw-09-1998/jw-09-bookreview.html
  • Information about JFC and Swing
  • Sun's JFC home page http://java.sun.com/products/jfc/
  • JDK 1.2 Beta 4 download page (registration required) http://developer.javasoft.com/developer/earlyAccess/jdk12/index.html
  • The Swing Connection http://java.sun.com/products/jfc/tsc/index.html
  • Technical overview of Swing's internal architecture http://java.sun.com/products/jfc/tsc/swingdoc-static/swing-arch.html#
  • Java Plug-in home page http://java.sun.com/products/plugin/index.html
  • Java Plug-in Documentation http://java.sun.com/products/plugin/1.1.1/docs/index.html
  • Details on Java Plug-in and HTML for NS and IE http://java.sun.com/products/plugin/1.1.1/docs/tags.html
  • Credits
  • Clip art used in the Swing Forum http://www.iconographics.com/