swing.gif (1610 bytes)JFC and Swing Introduction swing.gif (1610 bytes)



JFC stands for Java Fly Chicken. A 10 pieces meal is just $9.99

Actually, JFC is short for Java Foundation Classes, which encompasses a group of features to help people build graphical user interfaces (GUIs).

"Swing" was the codename of the project that developed the new components. Although it's an unofficial name, it's used frequently to refer to the new components and related API. It's immortalized in the package names for the Swing API, which begin with "javax.swing."

JFC was announced in 1997. It contains the following features:

The Swing Components
Cool and platform friendly (potentially wide choice of looks and feels indenpendent of platforms) components ranging from buttons to split panes to tables.
Accessibility API
Provide programmable interface to enables assistive technologies such as screen readers and Braille displays to get information from the user interface.
Java 2D API (JDK 1.2 only)
Programmable interface to allow developers to easily incorporate high-quality 2D graphics, text, and images in Java applications and applets. The style of programming is similar to GL or OpenGL.
Drag and Drop Support (JDK 1.2 only)
Provides the ability to drag and drop between a Java application and a native application.


Confusing Versions


Swing API version Corresponding
JFC 1.1 release
JDK 1.2 release
Swing 0.2 JFC 1.1
(with Swing 0.2)
none The first public release of JFC 1.1.
Swing 1.0.3 JFC 1.1
(with Swing 1.0.3)
none The release of JFC 1.1 included in Java Plug-in 1.1.1. Supported for use in shipping products.
Swing 1.1 Beta JFC 1.1
(with Swing 1.1 Beta)
JDK 1.2 Beta 4 The first JDK 1.2 release that used the same Swing package names as the corresponding JFC 1.1 release.
Swing 1.1 Beta 3 JFC 1.1
(with Swing 1.1 Beta 3)
JDK 1.2 RC1 The first release with the final Swing package names.
Swing 1.1 JFC 1.1
(with Swing 1.1)
JDK 1.2 FCS The first releases containing the final Swing 1.1 API that are supported for use in shipping products. Java Plug-in 1.1.2 and Java Plug-in 1.2 [PENDING: check] provide applet support for JDK 1.1 + Swing 1.1 and JDK 1.2, respectively.


There are 15 swing packages available:

javax.accessibility, javax.swing, javax.swing.border, javax.swing.colorchooser, javax.swing.event, javax.swing.filechooser, javax.swing.plaf, javax.swing.plaf.basic, javax.swing.plaf.metal, javax.swing.plaf.multi, javax.swing.table, javax.swing.text, javax.swing.text.html, javax.swing.tree, and javax.swing.undo

Most of the simple code can be done using



Creating Your First Swing Program

Example source program:

//import com.sun.java.swing.*; //Used by JDK 1.2 Beta 4 and all
                               //Swing releases before Swing 1.1 Beta 3.

import javax.swing.*;          //This is the final real package name.

import java.awt.*;             //The awt event model are still valid
import java.awt.event.*;

public class swingApp implements ActionListener 
    private JLabel label;
    private static String labelPrefix = "Number of button clicks: ";
    private int numClicks = 0;

    public swingApp() 
        //Create the top-level container.
        JFrame frame = new JFrame("SwingApplication");

        //Now create a button and label to go in it.
        JButton button = new JButton("I'm a Swing button!");

        label = new JLabel(labelPrefix + "0    ");

         * An easy way to put space between a top-level container
         * and its contents is to put the contents in a JPanel
         * that has an "empty" border.
        JPanel pane = new JPanel();
        pane.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
        pane.setLayout(new GridLayout(0, 1));

        //Add the JPanel to the frame.
        frame.getContentPane().add(pane, BorderLayout.CENTER);

        //Finish setting up the frame, and show it.
        frame.addWindowListener(new WindowAdapter() 
            public void windowClosing(WindowEvent e) 

    public void actionPerformed(ActionEvent e) {
        label.setText(labelPrefix + numClicks);
    public static void main(String[] args) {
        } catch (Exception e) 
            // Skip the exception and just get out for this sample program 

        new swingApp(); //Create and show the GUI.


javac swingApp.java


java swingApp

swingExample.jpg (4120 bytes)