Java Swing 2nd Edition Marc Loy pdf download
Java Swing 2nd Edition Marc Loy pdf download
https://ebookfinal.com/download/java-swing-2nd-edition-marc-loy/
https://ebookfinal.com/download/professional-c-2nd-edition-marc-
gregoire/
https://ebookfinal.com/download/get-rich-with-dividends-2nd-edition-
marc-lichtenfeld/
https://ebookfinal.com/download/head-first-java-2nd-edition-kathy-
sierra/
The Rope Swing Stories 1st Edition Jonathan Corcoran
https://ebookfinal.com/download/the-rope-swing-stories-1st-edition-
jonathan-corcoran/
https://ebookfinal.com/download/instructions-for-sports-medicine-
patients-2nd-edition-marc-safran/
https://ebookfinal.com/download/handbook-of-cosmetic-science-and-
technology-2nd-edition-marc-paye/
https://ebookfinal.com/download/the-secrets-of-house-music-
production-2nd-edition-marc-adamo/
https://ebookfinal.com/download/java-9-concurrency-cookbook-2nd-
edition-javier-fernandez-gonzalez/
Java Swing 2nd Edition Marc Loy Digital Instant
Download
Author(s): Marc Loy, Robert Eckstein, Dave Wood, James Elliott, Brian Cole
ISBN(s): 9780596004088, 0596004087
Edition: 2
File Details: PDF, 6.84 MB
Year: 2002
Language: english
Java Swing
Related titles from O’Reilly
Ant: The Definitive Guide Java Internationalization
Building Java Enterprise Applications Java Message Service
Database Programming with JDBC Java Network Programming
and Java Java NIO
Developing JavaBeans Java Performance Tuning
Enterprise JavaBeans Java Programming with Oracle JDBC
J2ME in a Nutshell Java Programming with Oracle SQLJ
Java 2D Graphics Java RMI
Java and SOAP Java Security
Java & XML JavaServer Pages
Java and XML Data Binding JavaServer Pages Pocket Reference
Java and XSLT Java Servlet Programming
Java Cookbook Java Threads
Java Cryptography Java Web Services
Java Distributed Computing JXTA in a Nutshell
Java Enterprise in a Nutshell Learning Java
Java Examples in a Nutshell Learning Wireless Java
Java Foundation Classes in a Nutshell
Also available
Java I/O
The Java Enterprise CD Bookshelf
Java in a Nutshell
SECOND EDITION
Java Swing
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly Media, Inc. books may be purchased for educational, business, or sales promotional use. On-
line editions are also available for most titles (safari.oreilly.com). For more information contact our cor-
porate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.
Printing History:
September 1998: First Edition.
November 2002: Second Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Java ™ Swing, Second Edition, the image of a spider monkey, and related trade dress
are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to
distinguish their products are claimed as trademarks. Where those designations appear in this book,
and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or
initial caps. Java and all Java-based trademarks and logos are trademarks or registered trademarks of
Sun Microsystems, Inc., in the United States and other countries. O’Reilly Media, Inc. is independent
of Sun Microsystems, Inc.
While every precaution has been taken in the preparation of this book, the publisher and authors
assume no responsibility for errors or omissions, or for damages resulting from the use of the
information contained herein.
ISBN: 978-0-596-00408-8
[M] [2012-03-09]
*
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
1. Introducing Swing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
What Is Swing? 1
Swing Features 5
Swing Packages and Classes 10
The Model-View-Controller Architecture 13
Working with Swing 16
The Swing Set Demo 17
Reading This Book 18
v
4. Labels and Icons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Labels 84
Working with Images 90
Support for HTML 93
Icons 94
Implementing Your Own Icons 95
Dynamic Icons 96
The ImageIcon Class 98
5. Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
The ButtonModel Interface 101
The DefaultButtonModel Class 104
The AbstractButton Class 106
The JButton Class 111
The JToggleButton Class 120
The JToggleButton.ToggleButtonModel Class 123
The JCheckBox Class 124
The JRadioButton Class 126
The ButtonGroup Class 128
vi | Table of Contents
8. Swing Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
A Simple Container 225
The Root Pane 228
Basic RootPaneContainers 246
The JFrame Class 246
The JWindow Class 251
The JApplet Class 254
Table of Contents | ix
23. Editor Panes and Editor Kits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849
The JEditorPane Class 849
Overview of the Editor Kits 854
HTML and JEditorPane 880
Hyperlink Events 885
The HTMLEditorKit Class 887
Extending HTMLEditorKit 891
Editing HTML 897
Writing HTML 900
Reading HTML 906
A Custom EditorKit 907
x | Table of Contents
27. Swing Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076
Utility Classes 1077
The Timer Class 1082
Tooltips 1085
Rendering Odds and Ends 1087
Event Utilities 1089
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1195
Table of Contents | xi
Preface
When Java was first released, its user interface facilities were a significant weakness.
The Abstract Window Toolkit (AWT) was part of the JDK from the beginning, but it
really wasn’t sufficient to support a complex user interface. It supported everything
you could do in an HTML form and provided free-standing frames, menus, and a
few other objects, but you’d be hard-pressed to implement an application as com-
plex as Quicken or Lotus Notes. AWT also had its share of portability problems; it
relied heavily on the runtime platform’s native user interface components, and it
wasn’t always possible to hide differences in the way these components behaved.
JDK 1.1 fixed a number of problems—most notably, it introduced a new event
model that was much more efficient and easier to use—but it didn’t make any major
additions to the basic components. We got a ScrollPane and a PopupMenu, but that
was about it. Furthermore, AWT still relied on the native components and therefore
continued to have portability problems.
In April 1997, Sun’s Java group (then called JavaSoft) announced the Java Founda-
tion Classes, or JFC, which supersedes (and includes) AWT. A major part of the JFC
was a set of much more complete, flexible, and portable user interface components
called “Swing.” (The JFC also includes a comprehensive facility for 2D graphics,
printing, and Drag and Drop.) With Swing, you can design interfaces with tree com-
ponents, tables, tabbed dialogs, tooltips, and a growing set of other features that
computer users are accustomed to.
In addition to the new components, Swing made three major improvements to the
AWT. First, Swing doesn’t rely on the runtime platform’s native components. It’s
written entirely in Java and creates its own components. This approach solved most
of the portability problems since components don’t inherit weird behaviors from the
runtime environment or do they work against its grain. Second, because Swing is in
complete control of the components, it’s in control of the way components look on
the screen and gives you more control over how your applications look. You can
xiii
* PDFs for the Java AWT Reference are available at this book’s web site, http://www.oreilly.com/catalog/
jswing2.
xiv | Preface
Preface | xv
Table
. P-1. Swing changes in the Java 2 SDK 1.3
xvi | Preface
Preface | xvii
xviii | Preface
Preface | xix
Conventions
This book follows certain conventions for font usage, property tables, and class dia-
grams. Understanding these conventions up-front makes it easier to use this book.
This book uses the following font conventions:
Italic
Used for filenames, file extensions, URLs, application names, emphasis, and
new terms when they are first introduced
Constant width
Used for Java class names, functions, variables, components, properties, data
types, events, and snippets of code that appear in text
Constant width bold
Used for commands you enter at the command line and to highlight new code
inserted in a running example
Constant width italic
Used to annotate output
Properties Tables
Swing components are all JavaBeans. Properties provide a powerful way to work
with JavaBeans, so we use tables throughout the book to present lists of properties.
Table P-3 is an example from the hypothetical JFoo class that shows how we use
these tables.
xx | Preface
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com