It don't mean a thing if it ain't got that Swing: A comparative review of four JFC/Swing books

The first wave of JFC/Swing books has hit the shores. Find out which -- if any -- of these four books delivers the goods on this complex and integral part of the JDK

Ignore JavaBeans, JDBC, RMI, Servlets, Java3D, Java's Security API, and so on, ad infinitum. Java's most important API is its sizzling Java Foundation Classes API, prominently featuring the Abstract Windowing Toolkit (AWT)'s long-awaited successor: the Swing GUI class library.

Why does JFC, and more specifically Swing, overshadow all other Java APIs? Because 99.9 percent of modern applications require rich GUI front ends. Whatever application domain you specialize in, we all need to clothe our applications in modern graphical user interfaces. This GUI facade doesn't only make or break modern applications, it also severely impacts your software development efforts. Huge chunks of your (and my) code are there purely and simply for the sake of user friendliness, and have nothing to do with core product functionality. GUIs are really the software equivalent of automatic transmissions, vanity mirrors, central locking, and adjustable seats in cars. That is, the essential non-essentials without which you don't sell products.

GUI capability was the sole reason for the often-criticized AWT's original raison d'etre. Unfortunately, AWT's multitude of flaws and imperfections have led many to feel that Java's original GUI capability is just another Java Achilles heel (performance being the first). Thankfully, JavaSoft seems quite adept at quickly and skillfully addressing Java aspects that fall below expectations (possibly excluding politically too-hot-to-handle issues like its unpopular Collections API), so we now have Java Foundation Classes (JFC) to relegate AWT to the history books.

If you're a regular visitor to Sun's Java Developer Connection (JDC) discussion groups, you know that the volume of GUI questions is at least an order of magnitude greater than for some other "hot" Java APIs. In light of this, I decided it was time JavaWorld took a closer look at books that aim to flatten the JFC/Swing learning curve, and bulldoze AWT from the Java map in the process. This month I'm reviewing four quick-off-the-mark JFC books (and, as always, taking my dope-test kit along.)

At the time of writing, four books were available that include the words Java Foundation Classes, JFC, or Swing in their titles:

  • Java Foundation Classes by Matthew T. Nelson (McGraw-Hill)
  • JFC: Java Foundation Classes by Daniel I. Joshi and Pavel A. Vorobiev (IDG Books)
  • Programming with JFC by Scott R. Weiner and Stephen Asbury (John Wiley)
  • Up to Speed with Swing: User Interfaces with Java Foundation Classes by Steven Gutz (Manning)

Note: Core Java Foundation Classes by Kim Topley, Cay S. Horstmann, and Gary Cornell (ISBN: 0130803014) was not available for review at press time.

Here's a bird's-eye view of each title's main attributes. The table orders the books by price.

Up to Speed with Swing (Manning)JFC: Java Foundation Classes (IDG Books)Java Foundation Classes (McGraw-Hill)Programming with JFC (John Wiley)
Price (US$)2.959.999.959.99
Pages, chapters (appendices)498, 13 (4)541, 11 (3)1040, 13 (0)560, 19 (2)
Listings density (lines/page)48445445
MVC frameworkYesYesNoNo
Pluggable look-and-feel frameworkYesNoYesYes
Document frameworkYesNoYesYes
Undo/redo frameworkNoYesNoYes
Drag-and-drop frameworkNoYesYesNo
Printing frameworkNoYesYes (*)No
Accessibility frameworkNoYesYesYes (*)
Java2DNoYes (*)YesNo
No. of "real-life" examplesNone442
Overall score7767

*Strictly speaking, yes, but only touched upon.

In the absence of tools to calculate the true cost-per-bit equivalent of a book, the Listings density row gives you an idea of how dense or "aerated" the source listings are. Low lines and/or page values usually mean unreadable listings and a high page-fill factor, so the higher this value, the better (up to some limit determined by your own eyesight, of course).

The MVC framework row indicates whether or not the text explains Swing's underlying Model-View-Controller design pattern.

The Pluggable look-and-feel framework row indicates whether or not the text explains and demonstrates Swing's pluggable look and feel (PLAF).

The Document framework row indicates whether or not the text attacks the nontrivial subject of Swing's Text Document framework (that is, package and its subpackages).

The Accessibility framework row indicates whether or not the text explains Swing's accessibility support for people with disabilities.

The Drag-and-drop framework row indicates whether or not the text discusses JFC's drag-and-drop support, as provided by the classes and interfaces in the java.awt.dnd package.

The Undo/redo framework row indicates whether or not the text discusses JFC's undo/redo support as provided by the classes and interfaces in the package.

The Java2D row indicates whether or not the text explores JFC's Java2D API. Most texts don't, since Java2D is most definitely a subject worthy of its own book(s). Any JFC books reviewed here that do write about Java2D do so only superficially.

The No. of "real-life" examples row indicates how many mini-projects are presented that begin to approach a real-life project.

Up to Speed with Swing: User Interfaces with Java Foundation Classes by Steven Gutz (Manning)

While the first part of this book's title is spot-on accurate, the second part isn't. Up to Speed with Swing is all about Swing's GUI component classes, and very little, if at all, about any of the other JFC APIs (see comparative table). Despite this little titling error (which publishers seem to make more and more often, and which always seems to broaden the scope of a book), the book's content does deliver on its title's core promise.

The book is subdivided into three parts: Part I, "Getting started;" Part II, "Swing components;" and Part III, "Advanced topics." Chapter 1, "A Java refresher," is really an AWT (and not Java) refresher that concentrates on event handling and layout managers, two aspects that have remained unchanged from AWT to Swing. Chapter 2, "Swing basics," therefore, is the beginning of the real meat on this particular bone. After an overview of the Swing packages, the author delves into the Model-View-Controller (MVC) design pattern, the architectural foundation for everything Swing -- especially its pluggable look and feel, custom rendering, and custom model capabilities. The chapter closes with a thorough "open-top bus tour" of class JComponent, the abstract grandaddy of all Swing GUI components.

Chapter 3, "Panels and panes," is the first in a list of chapters discussing Swing classes by logical grouping and steadily-increasing complexity. The remaining chapters in the list (4 through 11) include "Labels and buttons," "Text Management," "Progress bars, scroll bars, and sliders," "Menus and toolbars," "Dialogs and internal frames," "List boxes," "Trees," and "Tables." Together, these chapters form Part II, which is also the heart of the book (340 pages out of 500), and hence, the basis on which to judge the book as a whole.

For each class discussed in the text, the author provides an introduction, one or more examples on how to use the class, and reference-style information (a discussion of any class variables, constructors, and the most important class methods). This reference material is not grouped together and located at the end of the book as you might expect; instead, it is placed right after the example(s) for every discussed class. This reinforces the feeling that Up to Speed with Swing was designed according to a sensible pedagogical plan, meant to be read in a very linear fashion, building your understanding and experience of Swing with each passing chapter.

Finally, Part III consists of just two chapters, "Creating custom look-and-feel" (Chapter 12) and "Optimizing JFC Applications" (Chapter 13). The former chapter is very valuable, the topic being one that few JFC/Swing books tackle with vigor -- due, one suspects, to the daunting amount of work required to create a brand-new Swing look and feel. The last chapter in the book, on optimization, was disappointing. Its bulk is consumed with profiling and generic Java code optimizations -- not, as the chapter's title suggests, with any techniques specific to JFC and/or GUI implementation. Furthermore, the very few GUI-specific suggestions, which relate to the use of multiple threads, were flawed. The author claims that using Swing's Timer class is more CPU-efficient than using Thread.sleep() because the latter, according to the author, consumes cycles while sleeping (which is false, as any programmer who has studied properly implemented multithreaded or multitasking systems will confirm).

I found the author's consistent writing style and paced approach to introducing Swing classes very easy to follow, almost as if I was back in school with a good teacher in front of the class, explaining every detail slowly and clearly. For the more mature or adventurous reader, on the other hand, the code examples do not contain much that will excite the old gray matter: The examples demonstrate only how to instantiate every Swing component and exploit the resultant object's features. No cool example applications, no higher-level reusable classes, no creative uses -- just a straightforward course in how to use Swing classes. Clearly, beginning to intermediate programmers will appreciate Gutz's zero-risk, highly-focused approach, as the book truly will bring them "up to speed" on Swing.

One cautionary note: the first printing of this book contained many annoying errors. The publisher assures me that the second printing, which should be available by the time you read this, has been thoroughly corrected in this respect. In any event, the book and example source code are available in electronic form from the publisher's Web site, so as always, browse before you buy.

JFC: Java Foundation Classes by Daniel I. Joshi and Pavel A. Vorobiev (IDG Books)

JFC: Java Foundation Classes

is organized into four parts: Part I, "JFC Overview;" Part II, "JFC Services;" Part III, "JFC Case Studies;" and Part IV, "Quick Reference Section." Parts I and II really constitute a single logical group of chapters that introduce you to Swing's catalog of GUI components and JFC's other diverse services. Chapter 2, "Looking at Swing's Basic Components," is a whirlwind tour of Swing's simpler classes (that is, almost all classes except those relating to




). Chapter 3, "Handling Events," reviews Java's event delegation model, the use of inner classes for event handling, and JFC's new event classes. Chapter 4, "Using the Sophisticated Swing Components," tackles classes






, and


(the latter hardly being a "sophisticated component"). This chapter adequately deals with all the main programming obstacles of




: custom models, cell or path selection, custom editors, and custom renderers. (Steer well clear of any JFC/Swing book that doesn't go into these nontrivial subjects, which you will have to confront sooner or later.)

Chapter 5, "Text Operations Under the JFC," introduces a shift in approach and the beginning of Part II. Instead of focusing on individual GUI components, the authors start exploring JFC's many class frameworks. Chapter 5 deals with JFC's clipboard and undo/redo frameworks. (It is not a discussion of JFC's most complex framework, the Text Document framework -- though you'd be forgiven for thinking so, given the title of the chapter.) Chapter 6, "Printing Under the JFC," deals with Java's (still rather immature) printer and printing support framework. Chapter 7, "Tweaking a JFC User Interface," is not about custom components, nor custom rendering, nor even Swing's pluggable look and feel. Rather, it's about Swing's DebugGraphics and SwingUtilities classes, and Swing's enhanced keyboard support (keyboard shortcuts using KeyStroke objects). Chapter 8, "An Introduction to More JFC Enhancements," very briefly discusses accessibility by concentrating on event trapping rather than the arguably more-logical approach of exploring the package. Finally, still in Chapter 8, you'll find a thorough discussion of JFC's Drag-and-Drop API.

1 2 Page
Join the discussion
Be the first to comment on this article. Our Commenting Policies
See more