Java Swing 1998.pdf

(7149 KB) Pobierz
Microsoft Word - Java Swing -- O'REILLY.doc
3270066.001.png 3270066.002.png
Java Swing – O’Reilly
Java Swing
Copyright © 1998 O'Reilly & Associates, Inc. All rights reserved.
Printed in the United States of America.
Published by O'Reilly & Associates, Inc., 101 Morris Street, Sebastopol, CA 95472.
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 & Associates, Inc. is
independent of Sun Microsystems.
The O'Reilly logo is a registered trademark of O'Reilly & Associates, 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 & Associates, Inc. was aware of a trademark
claim, the designations have been printed in caps or initial caps. The use of the jukebox image in
association with Java™ Swing is a trademark of O'Reilly & Associates, Inc.
While every precaution has been taken in the preparation of this book, the publisher assumes no
responsibility for errors or omissions, or for damages resulting from the use of the information
contained herein.
Java Swing
What This Book Covers
About the Source Code
Conventions
Acknowledgments
1.1 What Is Swing?
1.2 Swing Features
1.3 Swing Packages and Classes
1.4 The Model-View-Controller Architecture
1.5 Working with Swing
1.6 The Swing Set Demo
1.7 Reading this Book
2. Jump Starting a Swing Application - 27
2.1 Upgrading Your Programs
2.2 Beyond Buttons
2.3 A Bigger Application
3.1 Understanding Actions
3.2 Sending Change Events in Swing
3.3 The JComponent Class
4. Labels and Icons - 74
4.1 Labels
4.2 Icons
5.1 Buttons
6.1 The Bounded-Range Model
- 2 -
Preface - 5
1. Introducing Swing - 10
3. Swing Component Basics - 44
5. Buttons - 88
6. Bounded Range Components - 112
Java Swing – O’Reilly
6.2 The JScrollBar Class
6.3 The JSlider Class
6.4 The JProgressBar Class
6.5 Monitoring Progress
7. Lists and Combo Boxes - 137
7.1 Lists
7.2 Representing List Data
7.3 Handling Selections
7.4 Displaying Cell Elements
7.5 The JList Class
7.6 Combo Boxes
7.7 The JComboBox Class
8.1 A Simple Container
8.2 Basic RootPaneContainers
9.1 Managing a Desktop
9.2 Building a Desktop
10.1 The JDialog Class
10.2 The JOptionPane Class
11. Specialty Panes and Layout Managers - 255
11.1 The JSplitPane Class
11.2 The JScrollPane Class
11.3 The JTabbedPane Class
11.4 Layout Managers
11.5 Other Panes
12.1 The JFileChooser Class
12.2 The File Chooser Package
12.3 The Color Chooser
12.4 The JColorChooser Class
13.1 Introducing Borders
13.2 Swing Borders
13.3 The CompoundBorder Class
13.4 Creating Your Own Border
14.1 Introducing Swing Menus
14.2 Menu Bar Selection Models
14.3 The JMenuBar Class
14.4 The JMenuItem Class
14.5 The JPopupMenu Class
14.6 The JMenu Class
14.7 Selectable Menu Items
14.8 Toolbars
15.1 Table Columns
15.2 Table Data
15.3 The JTable Class
15.4 Editing and Rendering
15.5 Selecting Table Entries
16. Advanced Table Examples - 449
- 3 -
8. Swing Containers - 178
9. Internal Frames - 208
10. Swing Dialogs - 232
12. Chooser Dialogs - 292
13. Borders - 327
14. Menus and Toolbars - 350
15. Tables - 400
Java Swing – O’Reilly
16.1 A Table with Row Headers
16.2 Large Tables with Paging
16.3 Charting Data with a TableModel
17.1 A Simple Tree
17.2 Tree Models
17.3 Tree Nodes and Paths
17.4 The JTree Class
17.5 Tree Selections
17.6 Tree Events
17.7 Rendering and Editing
17.8 What Next?
18.1 The Swing Undo Facility
19.1 The Swing Text Components
19.2 More to Come
20. Document Model and Events - 609
20.1 The Document Model
20.2 Document Events
20.3 Advanced AbstractDocument Event Model
21. Styled Documents and JTextPane - 658
21.1 Style
21.2 A Stylized Editor
22. Carets, Highlighters, and Keymaps - 730
22.1 JTextComponent UI Properties
23.1 Text Views
23.2 The View Classes
24.1 Overview of the Editor Kits
24.2 Phew!
25. Programming with Accessibility - 827
25.1 How Accessibility Works
25.2 The Accessibility Package
25.3 Other Accessible Objects
25.4 The Six Types of Accessibility
25.5 The Accessibility Utility Classes
25.6 Interfacing with Accessibility
26.1 How Does It Work?
26.2 Key L&F Classes and Interfaces
26.3 The MultiLookAndFeel
26.4 Look-and-Feel Customization
26.5 Creation of a Custom L&F
27.1 General Utilities
27.2 Editing and Rendering Utilities
27.3 Event Utilities
27.4 Image Utilities
28. Swing Under the Hood - 938
- 4 -
17. Trees - 466
18. Undo - 534
19. Text 101 - 578
23. Text Views - 749
24. EditorKits and TextActions - 788
26. Look & Feel - 858
27. Swing Utilities - 912
Java Swing – O’Reilly
28.1 Creating Your Own Component
28.2 Working with Focus
28.3 Lightweight vs. Heavyweight Components
28.4 Multithreading Issues with Swing
28.5 Painting and Repainting
A. Look & Feel Resources - 978
Colophon - 985
Preface
Since Java was first released, its user interface facilities have been 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 complex 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 of 1997, JavaSoft announced the Java Foundation Classes, or JFC, which supersedes (and
includes) AWT. A major part of the JFC is a new set of user interface components that is much
more complete, flexible, and portable. These new components are 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 components, tables, tabbed dialogs, tooltips, and many other features
that computer users have grown accustomed to.
In addition to the new components, Swing makes three major improvements on the AWT. First, it
doesn't rely on the runtime platform's native components. It's written entirely in Java, and creates its
own components. This new approach should solve the portability problem, since components don't
inherit the weird behaviors from the runtime environment. 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 of how your applications look. You can choose between several pre-built "look-and-
feels," or you can create your own if you want your software to show your personal style. This
feature is called "Pluggable Look-and-Feel" or PLAF. Third, Swing makes a very clear distinction
between the data a component displays (the "model") and the actual display (the "view"). While the
fine points of this distinction are appreciated mostly by computer scientists, it has important
implications for all developers. This separation means that components are extremely flexible. It's
easy to adapt components to display new kinds of data that their original design didn't anticipate, or
to change the way a component looks without getting tangled up in assumptions about the data it
represents.
The first official release of Swing, for use with JDK 1.1, took place in the spring of 1998. Swing
(and the rest of JFC) is a part of JDK 1.2, and is currently revolutionizing Java user interface
development. This book shows you how to join the revolution.
- 5 -
Zgłoś jeśli naruszono regulamin