Return to Course Content Home

Swing

Optional Reading

We will be using the Creating a GUI with JFC/Swing tutorial from Sun(Oracle) as a Reference source. You are not required to read the entire tutorial, I suggest you skim through it though to use a a supplement to what I give you here.

Background and Overview

When Java first came out, AWT was good enough to get people's interest. It wasn't a wonderful toolkit, but it had the basics, and it was better than a lot of other options. One of the biggest draws was that you could learn a windowing system that could be used on PCs, Suns, SGIs, and Macs! Considering the complexity of X-windows and the Windows Foundation Classes, this was a very big draw!

Initially, AWT was meant to bring life to web pages using Applets. The problem was that AWT didn't support other than some simple components and methods. That combined with consumers using dial-up (at best), downloading any type of complex Applet was a long, time-consuming process that turned people off.

Netscape (remember them?) was actually the real parent of Swing, they came up with the Internet Foundation Classes(IFC). The idea was to provide a more complete set of user controls. One of the key design features was that everything was a container, and you could easily nest elements. Sun liked it, they worked with Netscape and came up with the Java Foundation Classes (JFC a.k.a. Swing) in 1997.

Swing was designed to be a robust toolkit, providing users with many of the tools they'd need to create GUIs. As we wander down the Swing trail, you'll see that higher level, more complex components (like an editor or web browser) are missing from Swing. Personally, I think there are several reasons for this, some have to do with keeping the size of the JDK down, some are because Sun didn't want to alienate vendors who made these more complex components for sale.

One question that used to come up (but doesn't happen often any more) is that can you mix AWT visual components with Swing. The technical answer is yes, the practical answer is no. AWT and Swing really don't play well with each other for several reasons.

For a long time, one of the key facets of Swing was that with the exception of a few key classes, each class knew how to "draw" itself to the screen. It didn't rely on the underlying OS to provide components like buttons or color choosers.

As of JDK 1.5.0_08, Swing now uses native widget rendering for existing components in all Windows OS (XP and Vista). This guarantees the correct look and feel and now echoes the approach that IBM took with the Standard Widget Toolkit(SWT). As of JDK 1.6.0 Swing will use native widgets for Solaris and Linux as well
According to Swing team, this is the only way to maintain compatibility with ever changing look and feel variations.

As of Java SE Update 10, a new cross-platform look and feel (code name Nimbus) is provided. So the Ocean look and feel, like the Metal L&F, has come and gone. (Aren't shifting standards nice?)

Unlike some of the other Modules. I'm going to split this week into many different parts. Each part will cover different components within Swing.

Oh, and I recently found a very interesting website that will help you come up with color schemes for a web page. I played around with it and it looks quite nice, so for those of you ever looking for chromatic enlightenment, go to the Color Scheme Designer website.

As a final comment, many of you are wondering why are we messing with Swing, if it isn't used that much. Two reasons actually, it still is a very good introduction to GUIs, and much of what you will learn with Swing can be applied to many other GUI variations. In fact, most of the event handling and concepts of layout managers are directly applicable to the Google Web Toolkit, which we'll cover at the end of the course.

So...take a deep breath...and let's get started....