New to Java? We'll help you get started with our revised beginner's tutorial, or our free online textbook.

Get the latest Java books
h t t p : / /w w w . j a v a c o f f e e b r e a k . c o m /

Java Coffee Break


Learning Java

Author Profiles
Talk Java!

Using Java

Discuss Java

Looking for Java resources? Check out the Java Coffee Break directory!

Learning about Swing

The best way to learn about Swing is to actually use an application that has a Swing GUI. A good starting place is the SwingSet demo, that is shipped with JDK1.2.

SwingSet Demo

Figure 1 - SwingSet Demo

If you don't already have JDK1.2 installed, you'll need to install it to work with Swing applications. The latest version of JDK1.2 can be found at

Running the SwingSet Demo

The demo can be found in the demo/jfc/SwingSet directory, located under your JDK1.2 installation directory. From a DOS Prompt or shell window, change to this directory then run the SwingSet application.

c:\>cd \jdk1.2\demo\jfc\SwingSet
c:\jdk1.2\demo\jfc\SwingSet>java SwingSet

The first thing you should notice is that the demonstration takes awhile to load - a window with a progress bar will be shown as the demonstration loads. The progress bar component is a nice way of letting users know that a slow application is still chugging along, and hasn't fallen over ;)

Once the demonstration loads, you can then click on different tab buttons to view the various components and behaviors that make up the Swing API. Take some time to experiment and click on some of the components - you'll be pleasantly surprised at the functionality that's available.

While you have the SwingSet demo running, take a look at the menu options. You can now trigger a menu using only the keyboard (e.g. ALT-F for the File menu). Take a look at the Options menu, and the radio buttons provided. These allow you to dynamically change the look-and-feel of components at run-time.

L&F Options

Figure 2 - L&F Options

Switch between the Java L&F (also referred to as 'Metal'), and the Motif/Windows L&F. You'll notice that all of the components (including menus) change appearance. This is a very powerful feature of Swing, and gives users control over which GUI style is used. Personally, I think that the Metal L&F is very comfortable to use, though end-users may prefer to stick with Windows L&F.

Once you've had a play around with Swing, you'll be reluctant to go back to the older AWT components. Remember however that only the Java 2 Platform supports Swing (though older Java 1.1 Virtual Machines can still run Swing if you include the components in the codebase of your application). For the moment at least, it rules out developing Swing applets, unless the Java Plug-in is used to run them under a Java 2 Virtual Machine.

Developing your first Swing application

Back to main

Copyright 1998, 1999, 2000 David Reilly

Privacy | Legal | Linking | Advertise!

Last updated: Monday, June 05, 2006