This book is best described as a programmer?s guide, serving both as a reference and a tutorial. Emphasis is placed on using Swing to solve a broad selection of realistic and creative problems. We assume an intermediate knowledge of Java, including the basics of putting together an AWT-based GUI, how the event model works, and familiarity with anonymous and explicit inner classes. Those who do not have this background can pick it up in any beginner book on AWT or Swing. However, the first edition of this book has proven to be most useful to those who come to it with an intermediate understanding of Swing. For this reason we do not recommend this book to Swing beginners. For beginners we suggest Manning?s own Up to Speed with Swing by Steven Gutz.
Our goal was to produce a book that contains enough explanation and examples to satisfy the most demanding Swing developer. We feel we have accomplished this goal again with the updates in this edition, but please judge for yourself and we welcome all constructive feedback. Unlike the first edition, however, this version is not freely available on the publisher?s web site. The first edition will remain available online at www.manning.com/robinson2, but we hope that we have developed enough of a following to generate more sales with the second edition without giving it away for free. Let?s hope this is true!
Java 1.4 (aka Merlin) is the first major release of the Java platform that was planned through a Java Community Process (JCP), allowing participants outside of Sun to have an influence on the overall feature set. Each new feature, whether an addition or a change, had a dedicated expert group which handled the description of that functionality according to certain rules underlying Java Specification Requests (JSRs), which are the building blocks of any JCP. Similar to an open-source project, but with actual development still done by Sun engineers, this process allowed Java 1.4 to evolve for the first time in a democratic fashion. The result is a platform containing improvements that the Java community as a whole voted for, not just Sun.
This updated edition of Swing contains many new examples, revised text, and
additional material to bring the book up to date with Java 1.4. This includes
complete coverage of the new JSpinner and JFormattedTextField
components, the new focus and keyboard architectures, scrollable tabbed panes,
indeterminate progress bars, variable height JTable rows, and many
other new features. Larger changes to the book include the addition of three
new chapters: ?Constructing an HTML Editor Applications,? ?Constructing an XML
Editor,? and ?Drag and Drop? with Swing. A new appendix on Java Web Start has
also been added and all examples throughout the book have been enhanced to conform
to the Java look and feel design guidelines.
In general, each chapter starts with class and interface explanations occasionally interspersed with small examples to demonstrate key features. The bulk of each chapter is then devoted to the construction of several larger examples, often building on top of previous examples, illustrating more complex aspects of the components under investigation.
Part I contains two chapters that introduce Swing and discuss the most significant mechanisms underlying it. The first chapter is a brief overview that we suggest for all Swing newcomers. More experienced developers will want to read straight through most of chapter 2, as it provides an understanding of Swing?s most significant underlying behavior. This chapter is referenced throughout the book, and we expect all readers to refer to it often. At minimum we recommend that all readers skim this chapter to at least get a rough idea of what is covered.
Part II consists of twelve chapters covering all the basic Swing components with detailed descriptions and helpful examples of each. These chapters discuss the bread and butter of Swing-based GUIs, and each includes usage guidelines written by a usability and interface design expert.
Part III contains seven chapters dealing with the more advanced components. These chapters are significantly more complex than those in part II, and they require a thorough understanding of Swing's architecture, as well as the basic Swing components.
Part IV consists of three chapters on special topics with a focus on Swing, including printing, constructing an XML editor application, and implementing Drag and Drop.
Most examples are presented in three distinct parts:
The code: After a general introduction to the example, including one or more screenshots, the underlying code is listed. Annotations appear to the right of significant blocks of code to provide a brief summary of its purpose. Each annotation has a number which links it to the explanation of that code in the Understanding the code section.
Understanding the code: This section contains a detailed explanation of the code. Most paragraphs are accompanied by a number which links that text with the associated annotated code listed in the code section.
Running the code: After the code is explained, this brief section provides suggestions for testing the program. This section may also include references and suggestions for taking the example further.
NOTE Throughout the book we point out specific behaviors or functionality that either differs from what is expected or that can be achieved through alternate techniques. We also use this icon to denote various other types of notes, such as a reference or suggested background knowledge for the material being discussed.
Java 1.3 We use this mark wherever a new feature or update is introduced from Java 1.3.
Java 1.4 We use this mark wherever a new feature or update is introduced from Java 1.4.
BUG ALERT Occasionally, incorrect or unexpected behavior is caused by known Swing bugs. We do not attempt to hide or gloss over these; rather, we explicitly discuss these bugs and explain possible workarounds or fixes where applicable.
David Anderson, a usability and interface design expert, has provided detailed usage guidelines throughout the book. These guidelines do not represent hard-and-fast rules, but they are highly recommended for the development of consistent, user-friendly interfaces (see appendix B for David's references and recommended UI design readings).
All source code appears in Courier font. For example:
public void main( String args[] ) {
Example myExample = new Example();
}
We prefix all instance variables with ?m_,? and capitalize all static variables with underscores separating compound words. For example:
protected int m_index;
protected static int INSTANCE_COUNT;
Many examples are built from examples presented earlier in the book. In these cases we have minimized the amount of repeated code by replacing all unchanged code with references to the sections that contain that code. All new and modified code of any class is highlighted in bold. When a completely new class is added, we do not highlight that class in bold (the only exceptions to this rule are anonymous inner classes).
Purchase of Swing Second Edition includes free access to a private Internet forum where you can make comments about the book, ask technical questions, and receive help from the authors and from other Swing users. To access the forum, point your web browser to www.manning.com/robinson2. There you will be able to subscribe to the forum. This site also provides information on how to access the forum once you are registered, what kind of help is available, and the rules of conduct on the forum.
Matt can be contacted directly at matt@mattrobinson.com.
Pavel can be contacted directly at pvorobiev@yahoo.com.
David Anderson, author of the UI Guidelines, can be contacted through www.uidesign.net.
All source code for the examples presented in Swing Second Edition is available from www.manning.com/robinson2.