From Sun Microsystems Press and Prentice Hall comes the definitive guide to Swing: an exhaustive reference spanning more than 1600 pages. Clearly and concisely written and loaded with illustrative code examples, Graphic Java provides the most comprehensive Swing coverage available.
Part I (360 pages) discusses fundamental Swing concepts such as Swing component architecture, the JComponent class, borders, icons, actions, Swing and multithreading, Swing utilities, and pluggable look and feel.
Swing components are the focus throughout the rest of the book. In addition to code examples that illustrate component use, components are further explored with class diagrams, property and event tables, and a look at AWT compatibility. The final third of the book is devoted to Swing's most complex components: lists, combo boxes, tables, trees, and the text package.
"synopsis" may belong to another edition of this title.
David Gearywas lead engineer for the user interface toolkit for JavaSoft's Java Management API. He has been developing GUIs and using object-oriented technology since 1984, including C++, Smalltalk, Eiffel, Objective-C and now Java. He is currently an independent Java consultant.
7966G-2
Master the Java Foundation Classes with Graphic Java 2, the most complete and comprehensive guide to the AWT, Swing, and the 2D API
VOLUME 2: SWING (This is a 2 Volume set)
Swing gives Java application programmers world-class tools for building professional, customizable cross-platform GUIs. This comprehensive reference by former Sun engineer David Geary shows experienced programmers how to take full advantage of Swing's power. Practical explanations and robust code examples provide the resources you need to build Java applications with sophisticated graphical user interfaces.
Graphic Java is the one exhaustive reference that contains everything you need to know about Swing. In depth explanations are coupled with class diagrams and code examples for all of the key components, including:
You'll discover the key design considerations associated with Swing development, including Swing's object-oriented idioms and design patterns, and the pluggable look and feel architecture. You will understand how to use the Swing components, but more importantly you will have an understanding of how the components are designed and how they fit together within the Swing framework.
Preface
This book has been my full-time passion for more than a year. After Sun closed its office in Colorado Springs in August of 1997, I decided to forego traditional employment to give the Graphic Java series my complete attention. I was determined that the Swing volume would be the definitive guide to Swing, which meant that it had to be the most comprehensive, accurate and insightful Swing book available. I believe that to be the case, but of course, you will be the final judge.
Before I began writing, I spent a considerable amount of effort designing a book that would be beneficial to Swing novices in addition to developers with some Swing experience. As a software developer who has used numerous object oriented GUI frameworks, I realized that the fastest way to climb a framework's learning curve is to study code examples that illustrate specific concepts. As a result, code examples are the foundation upon which this book is built; nearly 300 code examples are discussed in detail--an average of approximately one code example every 5 pages.
However, code examples in and of themselves, cannot suffice as a reference for developers who have advanced along the Swing learning curve. As a result, every Swing component discussion is accompanied by a component summary that includes class diagrams, an examination of the component's properties and events and a class summary that discusses the public and protected methods implemented by the component.
The first part of this book explores fundamental aspects of Swing including:
Swing applets and applications
Swing and multithreading
Swing's Model-View-Controller architecture
Pluggable Look And Feel
The JComponent class
Borders, icons and actions
Miscellaneous features including timers and Swing utilities
The second part of the book examines Swing's components in detail. Numerous code examples are discussed for every Swing component, from labels and buttons to tables, trees and the text package. For example, more than 150 pages containing 25 code examples are dedicated to the table component, and 120 pages and 20 code examples illustrate how to get the most out of the tree component.
Audience
This book assumes that the reader has a good grasp of the Java language including recent additions to the language such as inner classes. This book also assumes a rudimentary understanding of the AWT; specifically, the delegation event model and the Component and Container classes upon which all Swing components are based. See "Graphic Java 2 Mastering the JFC Volume I: AWT" for a thorough investigation of AWT infrastructure and components.
How To Use This Book
Before diving into the Swing components, it is useful to have an understanding of fundamental concepts such as Swing's Model-View-Controller (MVC) design and pluggable look and feel. The former is discussed in "Swing Component Architecture" on page 71 and the latter is covered in the "Pluggable Look and Feel" on page 317. It is also important to understand the services provided by the JComponent class, which is the ultimate superclass of all lightweight Swing components. The JComponent class is examined in "The JComponent Class" on page 123.
Component Summaries
Each Swing component is introduced with numerous code examples that illustrate various component features. Code examples are followed by component summaries, such as the JScrollPane component summary that is partially listed below.
Component summaries begin with a listing of the component's model, UI delegate, renderer and editor, in addition to the events fired by the component. If a component is a replacement for an AWT component, the AWT component is also listed.
JScrollPane
----
javax.swing.plaf.basic.BasicScrollPaneUI
----
----
PropertyChangeEvent
java.awt.ScrollPane
The static relationships that a component maintains with other objects are illustrated with a class diagram, such as the class diagram for the JScrollPane class shown above. Class diagrams are introduced in Appendix A, Class Diagrams .
Properties
Property tables, such as the property table for the JScrollPane class shown below, are used to communicate a component's properties. Property tables include property names, the property's data type and whether a property is boolean, bound (a property change event is fired when the property is changed), simple (no events are fired when the property is changed), constrained (changes to the property can be vetoed), or indexed (a parameter, usually an integer , is used to access the property).
Some properties can be specified when a component is instantiated, and a component may provide setter and getter methods for a property. The manner in which a property can be specified is listed in the Access column of a property table.
Property tables also include a column for property default values.
Property tables are followed by a short description of each of the properties listed in the table.
JScrollPane Properties
Property Name
Data Type
Property Type
Access
Default
columnHeader
JViewport
B
SG
null
columnHeaderView
Component
B
S
null
corner
Component
IB
SG
null
horizontalScrollbar
JScrollBar
B
SG
----
horizontalScrollbarPolicy
int
B
CSG
As needed
rowHeader
JViewport
B
SG
null
rowHeaderView
Component
B
S
null
verticalScrollbar
JScrollBar
B
SG
----
verticalScrollbarPolicy
int
B
CSG
As needed
viewport
JViewport
B
SG
JViewport
viewportBorder
Border
B
SG
null
viewportView
Component
B
CSG
null
columnHeader
-- An instance of JViewport for the column header.
columnHeaderView
-- An instance of Component used as the column header viewport's view.
corner
-- A component that is displayed in one of the
scrollpane's corners. The corner is specified by one of the following strings:
ScrollPaneConstants.UPPER_LEFT_CORNER
ScrollPaneConstants.LOWER_LEFT_CORNER
ScrollPaneConstants.UPPER_RIGHT_CORNER
ScrollPaneConstants.LOWER_RIGHT_CORNER
horizontalScrollbar
-- The horizontal scrollbar used by the
scrollpane. The scrollbar is an instance of JScrollPane.ScrollBar , an extension of JScrollBar that takes into account whether the view contained in the scrollpane implements the Scrollable interface.
The remaining property descriptions for the JScrollPane class are omitted.
Events
Code examples are presented that illustrate event handling for a component. For example, the Tree chapter provides five code examples that illustrate handling of tree mouse, editing, selection, and expansion events.
Class Summaries
Each component summary concludes with a class summary that provides descriptions of the component's constructors and methods, such as the class summary for the JScrollPane class listed below.
JScrollPane
JComponent
ScrollPaneConstants, javax.accessibility.Accessible
public JScrollPane()
public JScrollPane(int vsbPolicy, int hsbPolicy)
public JScrollPane(Component view)
public JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
JScrollPane provides four constructors. The integer values passed to JScrollPane
constructors represent the vertical and horizontal scrollbar display policies, in that order. The component passed to the constructors is used as the viewport's view, meaning it is the component that is scrolled by the
scrollpane.
The no-argument constructor constructs a scrollpane with a null component for the viewport's view, and scrollbar display policies that display both the horizontal and vertical scrollbars as needed.
Creation Methods
public JScrollBar createHorizontalScrollBar()
public JScrollBar createVerticalScrollBar()
protected JViewport createViewport()
Like most Swing components, JScrollPane
provides create... methods that create its subcomponents. Unlike most Swing components however, JScrollPane implements the methods that create its scrollbars as public instead of protected because the methods are invoked from the scrollpane's UI delegate.
The createHorizontalScrollBar and createVerticalScrollBar methods both return instances of JScrollPane.ScrollBar , which is an extension of JScrollBar that takes into account whether the scrollpane's view implements the Scrollable
interface. See Interface Summary 13-2 on page 779 for more information on the Scrollable interface.
The createViewport method returns an instance of JViewport that is used as the
scrollpane's default viewport.
As with all Swing components that implement create... methods, the methods can be overridden in extension classes to replace the default sub-components with custom versions.
The remaining method descriptions for the JScrollPane class are omitted.
Swing Bugs
Swing has come a long way in terms of quality. The early beta releases contained numerous bugs, many of which have subsequently been fixed. However, like any software, Swing still has its share of bugs. Throughout this book, I have tried to point out as many bugs as possible so that developers can avoid the frustration of debugging code only to discover that a problem is due to a Swing bug.
It is also important to keep in mind that this book is based on Swing 1.1 FCS. As we went to press, a 1.1.1 version of Swing was released that was mostly a bug fix release. Therefore, it is a certainty that some of the bugs cited in this book will have been fixed by the time this book is on the shelves.
Using the CD-ROM
The CD in the back of the book contains the following:
1.1.7 JDK and Swing 1.1.1
1.2 JDK and Swing 1.1 FCS
Code examples from this book
Swing and the JDK
As mentioned previously, Swing 1.1.1 is mostly a bug fix release. Swing 1.1.1 does not work with the 1.2 JDK, and therefore the 1.1.7 JDK is included on the CD. Swing 1.1 FCS works with both the 1.1.7 and 1.2 versions of the JDK.
Code Examples from the Book
All of the code examples in this book that are accompanied by a CD-ROM icon are included on the CD in the back of the book. Figure P-1 shows the directory structure for the code examples. A directory exists for every chapter in the book, and subdirectories are included for each example, which should make it trivial to locate examples. For instance, Example 3-1 on page 91 can be found in the chapters/3/1 directory.
Every example is compiled and ready to run. Some of the directories representing code examples contain a README.txt file if the examples exhibit bugs or have been modified from their listing in the book.
The CD also contains two versions of the GridBagLab application that comes with "Graphic Java 2 Mastering the JFC Volume I: AWT." One version uses external windows and another uses Swing internal frames. The application provides an example of a fairly complete Swing application and illustrates the use of Swing internal frames. Additionally, the application can be used to explore the intricacies of the GridBagLayout layout manager.
Applets Vs. Applications
Most of the code examples discussed in this book are applets, but a fair percentage of examples are applications. Applications are typically implemented instead of applets either because files are manipulated or dialogs are shown--applets have restricted access to files, and under JDK 1.2 dialogs displayed from an applet contain a warning string. Sometimes applications are implemented instead of applets simply for the sake of variety. Nearly all of the applications discussed in this book that do not manipulate files can easily be rewritten as applets.
Conventions Used in This Book
Table P-1 shows the coding conventions used in this book. Coding Conventions
Convention
Example
Class names have initial capital letters.
public class ClassName
Method names have initial lower case and the rest of the words have an initial capital letter.
getLength()
Variable names have initial lower case and the rest of the words have an initial capital letter.
private int length
private int bufferLength
Note that, for the most part, methods are referred to without their arguments; however, arguments are included when the discussion warrants them.
Table P-2 shows the typographic conventions used in this book.
Typographic Conventions
Typeface or Symbol
Description
Indicates that the accompanying code, command, or file is available on the CD that accompanies this book.
courier
Indicates a command, file name, class name, method, argument, Java keyword, HTML tag, file content, or code excerpt.
bold courier
Indicates a sample command-line entry.
italics
Indicates definitions, emphasis, a book title, or a variable that should be replaced with a valid value.
From the Preface
This book has been my full-time passion for more than a year. After Sun closed its office in Colorado Springs in August of 1997, I decided to forego traditional employment to give the Graphic Java series my complete attention. I was determined that the Swing volume would be the definitive guide to Swing, which meant that it had to be the most comprehensive, accurate and insightful Swing book available. I believe that to be the case, but of course, you will be the final judge.
Before I began writing, I spent a considerable amount of effort designing a book that would be beneficial to Swing novices in addition to developers with some Swing experience. As a software developer who has used numerous object oriented GUI frameworks, I realized that the fastest way to climb a framework's learning curve is to study code examples that illustrate specific concepts. As a result, code examples are the foundation upon which this book is built; nearly 300 code examples are discussed in detail - an average of approximately one code example every 5 pages.
However, code examples in and of themselves, cannot suffice as a reference for developers who have advanced along the Swing learning curve. As a result, every Swing component discussion is accompanied by a component summary that includes class diagrams, an examination of the component's properties and events and a class summary that discusses the public and protected methods implemented by the component.
The first part of this book explores fundamental aspects of Swing including:
Swing applets and applications
Swing and multithreading
Swing's Model-View-Controller architecture
Pluggable Look And Feel
The JComponent class
Borders, icons and actions
Miscellaneous features including timers and Swing utilities
The second part of the book examines Swing's components in detail. Numerous code examples are discussed for every Swing component, from labels and buttons to tables, trees and the text package. For example, more than 150 pages containing 25 code examples are dedicated to the table component, and 120 pages and 20 code examples illustrate how to get the most out of the tree component.
"About this title" may belong to another edition of this title.
FREE shipping within U.S.A.
Destination, rates & speedsSeller: Better World Books, Mishawaka, IN, U.S.A.
Condition: Good. 3rd. Used book that is in clean, average condition without any missing pages. Seller Inventory # GRP73130840
Quantity: 1 available
Seller: ZBK Books, Carlstadt, NJ, U.S.A.
Condition: good. Used book in good and clean conditions. Pages and cover are intact. Limited notes marks and highlighting may be present. May show signs of normal shelf wear and bends on edges. Item may be missing CDs or access codes. May include library marks. Fast Shipping. Seller Inventory # ZWM.EGXY
Quantity: 1 available
Seller: SecondSale, Montgomery, IL, U.S.A.
Condition: Good. Item in good condition. Textbooks may not include supplemental items i.e. CDs, access codes etc. Seller Inventory # 00046809412
Quantity: 4 available
Seller: ThriftBooks-Atlanta, AUSTELL, GA, U.S.A.
Paperback. Condition: Fair. No Jacket. Readable copy. Pages may have considerable notes/highlighting. ~ ThriftBooks: Read More, Spend Less 2.6. Seller Inventory # G0130796670I5N00
Quantity: 1 available
Seller: Wonder Book, Frederick, MD, U.S.A.
Condition: Good. Good condition. With CD! A copy that has been read but remains intact. May contain markings such as bookplates, stamps, limited notes and highlighting, or a few light stains. NOT AVAILABLE FOR SHIPMENT OUTSIDE OF THE UNITED STATES. Seller Inventory # J04A-04033
Quantity: 1 available
Seller: WorldofBooks, Goring-By-Sea, WS, United Kingdom
Paperback. Condition: Very Good. The book has been read, but is in excellent condition. Pages are intact and not marred by notes or highlighting. The spine remains undamaged. Seller Inventory # GOR002493626
Quantity: 2 available
Seller: AwesomeBooks, Wallingford, United Kingdom
Paperback. Condition: Very Good. Graphic Java 2, Volume 2: Swing Components (The Sun Microsystems Press Java Series) This book is in very good condition and will be shipped within 24 hours of ordering. The cover may have some limited signs of wear but the pages are clean, intact and the spine remains undamaged. This book has clearly been well maintained and looked after thus far. Money back guarantee if you are not satisfied. See all our books here, order more than 1 book and get discounted shipping. Seller Inventory # 7719-9780130796677
Quantity: 1 available
Seller: Bahamut Media, Reading, United Kingdom
Paperback. Condition: Very Good. This book is in very good condition and will be shipped within 24 hours of ordering. The cover may have some limited signs of wear but the pages are clean, intact and the spine remains undamaged. This book has clearly been well maintained and looked after thus far. Money back guarantee if you are not satisfied. See all our books here, order more than 1 book and get discounted shipping. Seller Inventory # 6545-9780130796677
Quantity: 1 available
Seller: BennettBooksLtd, North Las Vegas, NV, U.S.A.
Paperback. Condition: New. In shrink wrap. Looks like an interesting title! Seller Inventory # Q-0130796670
Quantity: 1 available