You are previewing Java Swing.
O'Reilly logo
Java Swing

Book Description

The Swing classes eliminate Java's biggest weakness: its relatively primitive user interface toolkit. Swing provides many new components and containers that allow you to build sophisticated user interfaces, far beyond what was possible with AWT. The old components have been greatly improved, and there are many new components, like trees, tables, and even text editors. It also adds several completely new features to Java's user interface capabilities: drag-and-drop, undo, and the ability to develop your own "look and feel," or the ability to choose between several standard looks. The Swing components are all "lightweight," and therefore provide more uniform behavior across platforms, making it easier to test your software. All these new features mean that there's a lot to learn. Swing is undoubtedly way ahead of AWT -- or, for that matter, any widely available user interface toolkit -- but it's also a lot more complicated. It's still easy to do simple things. But once you've seen what's possible, you won't want to do the simple things. Java Swing gives you in-depth coverage of everything you need to know to take full advantage of Swing, providing detailed descriptions of every class and interface in the key Swing packages. It shows you how to use all of the new components, allowing you to build state-of-the-art user interfaces. It also discusses how the components implement the MVC (Model View Controller) architecture, so you can understand how the components are designed and subclass them intelligently. Finally, it shows how to create your own "look and feel." Throughout, Java Swing focuses on giving you the context you need to understand what you're doing. It's more than documentation; Java Swing helps you develop code quickly and effectively. Whether you're a serious Java developer, or just trying to find out what Java can do, you'll find Java Swing an indispensable guide.

Table of Contents

  1. Java Swing
    1. Preface
      1. What This Book Covers
      2. About the Source Code
      3. Conventions
      4. Acknowledgments
    2. 1. Introducing Swing
      1. What Is Swing?
        1. What Are the Java Foundation Classes (JFC)?
        2. Is Swing a Replacement for AWT?
        3. Rethinking the AWT
        4. JFC vs. AFC
      2. Swing Features
        1. Pluggable Look-and-Feels
        2. Lightweight Components
        3. Additional Features
        4. How Can I Use Swing?
      3. Swing Packages and Classes
        1. Swing Packages
        2. Class Hierarchy
      4. The Model-View-Controller Architecture
        1. MVC Interaction
        2. MVC in Swing
      5. Working with Swing
        1. Multithreading
        2. The Z-Order Caveat: Lightweight and Heavyweight Components
      6. The Swing Set Demo
      7. Reading this Book
    3. 2. Jump Starting a Swing Application
      1. Upgrading Your Programs
        1. A Simple AWT Application
        2. Including Your First Swing Component
      2. Beyond Buttons
        1. What Is an Internal Frame?
      3. A Bigger Application
    4. 3. Swing Component Basics
      1. Understanding Actions
        1. Actions and Containers
        2. The Action Interface
          1. Property
          2. Methods
          3. Events
        3. The AbstractAction Class
          1. Properties
          2. Events
          3. Protected Fields
          4. Constructors
          5. Methods
          6. Using an Action
      2. Sending Change Events in Swing
        1. The ChangeEvent Class
          1. Constructor
        2. The ChangeListener Interface
          1. Method
      3. The JComponent Class
        1. Inherited Properties
          1. Other Methods
        2. JComponent Properties
          1. UI Delegates and UIClassIDs
          2. Invalidating and Repainting
          3. The paint( ) Method and Opaqueness
          4. Position, Size, and Alignment
          5. Adding Borders
          6. Working with Tooltips
          7. Client Properties
          8. Double Buffering
          9. Serialization
          10. Debug Graphics
          11. Focus and Focus Cycle
          12. Keyboard Events
          13. Accessibility
        3. Events
          1. Event Methods
        4. Fields and Methods
          1. Protected Fields
          2. Constructor
          3. Graphics
          4. Focus
          5. Keyboard Actions
          6. Tooltips
          7. Client Properties
          8. Event Handlers
          9. Miscellaneous
    5. 4. Labels and Icons
      1. Labels
        1. The JLabel Class
          1. Properties
          2. displayedMnemonic and labelFor Properties
          3. Alignment
          4. Working with Images
          5. Events
          6. Constant
          7. Field
          8. Constructors
          9. User Interface Method
          10. Other Public Method
          11. Protected Methods
      2. Icons
        1. The Icon Interface
          1. Properties
          2. Method
          3. Implementing Your Own Icons
          4. Dynamic Icons
        2. The ImageIcon Class
          1. Properties
          2. Serialization
          3. Protected Constants
          4. Constructors
          5. User Interface Method
          6. Protected Method
    6. 5. Buttons
      1. Buttons
        1. The ButtonModel Interface
          1. Properties
          2. Events
        2. The DefaultButtonModel Class
          1. Properties
          2. Events
          3. Constants
          4. Protected Fields
          5. Constructor
        3. The AbstractButton Class
          1. Properties
          2. Events
          3. Constants
          4. Protected Fields
          5. Constructor
          6. User Interface Methods
          7. Other Public Methods
          8. Protected Methods
        4. The JButton Class
          1. Properties
          2. Using the Default Button
          3. Events
          4. Constructors
          5. User Interface Method
          6. Using Mnemonics
          7. Fancy Buttons
        5. The JToggleButton Class
          1. Properties
          2. Events
          3. Constructors
          4. User Interface Method
        6. The JToggleButton.ToggleButtonModel Class
          1. Properties
        7. The JCheckBox Class
          1. Properties
          2. Events
          3. Constructors
          4. User Interface Method
        8. The JRadioButton Class
          1. Properties
          2. Events
          3. Constructors
          4. User Interface Method
          5. Opaque JRadioButtons and JCheckBoxes
        9. The ButtonGroup Class
          1. Properties
          2. Voting with a Button Group
          3. Protected Field
          4. Constructor
          5. Methods
    7. 6. Bounded Range Components
      1. The Bounded-Range Model
        1. Properties
        2. Events
        3. Method
        4. The DefaultBoundedRangeModel Class
          1. Properties
          2. Events
          3. Fields
          4. Constructors
          5. Miscellaneous
          6. Working with the Bounded-Range Model
      2. The JScrollBar Class
        1. Properties
        2. Events
        3. Protected Fields
        4. Constructors
        5. Miscellaneous
        6. Handling Events from a Scrollbar
      3. The JSlider Class
        1. Properties
        2. Client Properties
        3. Events
        4. Protected Fields
        5. Constructors
        6. Labels
        7. Miscellaneous
        8. Creating a Slider
      4. The JProgressBar Class
        1. Properties
        2. Events
        3. Protected Fields
        4. Constructors
        5. Miscellaneous
        6. Working with Progress Bars
      5. Monitoring Progress
        1. The ProgressMonitor Class
          1. Properties
          2. Constructor
          3. Miscellaneous
          4. Using a Progress Monitor
        2. The ProgressMonitorInputStream
          1. Property
          2. Constructor
          3. Methods
          4. Using a ProgressMonitorInputStream
    8. 7. Lists and Combo Boxes
      1. Lists
        1. Anatomy of a Swing List
        2. Where To Go from Here?
      2. Representing List Data
        1. The ListModel Interface
          1. Properties
          2. Events
        2. The AbstractListModel Class
          1. Protected Fields
          2. Methods
        3. The DefaultListModel Class
          1. Properties
          2. Constructor
          3. Methods
          4. A JList with Changing Contents
        4. ListDataEvent
          1. Properties
          2. Constants
          3. Constructor
        5. The ListDataListener Interface
          1. Methods
      3. Handling Selections
        1. The ListSelectionModel Interface
          1. Properties
          2. Constants
          3. Methods
          4. Events
        2. The DefaultListSelectionModel Class
          1. Properties
          2. Events
          3. Protected Field
          4. Constructor
          5. Method
          6. Working with the ListSelectionModel
        3. ListSelectionEvent
          1. Properties
          2. Constructor
          3. Methods
        4. ListSelectionListener
          1. Listening for ListSelectionEvents
      4. Displaying Cell Elements
        1. The ListCellRenderer Interface
          1. Implementing a Cell Renderer
        2. The DefaultListCellRenderer Class
      5. The JList Class
        1. Properties
        2. Constructors
        3. Miscellaneous
        4. Selection Model
        5. Scrolling
        6. Data Model
        7. User Interface
        8. Events
        9. The Java Books Example
      6. Combo Boxes
        1. The ComboBoxModel Interface
          1. Property
          2. Events
        2. The MutableComboBoxModel Interface
        3. The DefaultComboBoxModel Class
          1. Constructors
          2. Methods
          3. Events
        4. ComboBoxEditor
          1. Properties
          2. Events
          3. Implementing a Custom Editor
      7. The JComboBox Class
        1. The Key Selection Manager
          1. Properties
          2. Events
          3. Constructors
          4. Methods
          5. List Methods
          6. Key Selection
          7. Internal Methods
        2. Java Books Revisited
    9. 8. Swing Containers
      1. A Simple Container
        1. The JPanel Class
          1. Properties
          2. Constructors
          3. Method
          4. Opacity
          5. The Box Class
        2. The Root Pane
        3. The JRootPane Class
          1. Understanding the Glass Pane
          2. Avoiding Unnecessary Layers
          3. Properties
          4. Revalidate
          5. Protected Fields
          6. Constructors
          7. Public Methods
          8. Protected Methods
          9. Inner Classes
        4. The RootPaneContainer Interface
          1. Properties
        5. The JLayeredPane Class
          1. Properties
          2. Constants
          3. Constructor
          4. Adding Components to Layers
          5. Layer Management Methods
          6. Other Public Method
          7. Static Methods
          8. Protected Methods
      2. Basic RootPaneContainers
        1. The WindowConstants Interface
          1. Constants
        2. The JFrame Class
          1. Properties
          2. Protected Fields
          3. Constructors
          4. User Interface Methods
          5. Protected Methods
          6. Exiting Frames
        3. The JWindow Class
          1. Properties
          2. Protected Fields
          3. Constructors
          4. Protected Methods
        4. The JApplet Class
          1. Hiding the Warning Message
          2. Threading Issues
          3. Properties
          4. Protected Fields
          5. Constructor
          6. User Interface Methods
          7. Protected Methods
    10. 9. Internal Frames
      1. Managing a Desktop
        1. Overview
        2. The JInternalFrame Class
          1. Properties
          2. Events
          3. Constants
          4. Protected Fields
          5. Constructors
          6. JLayeredPane Methods
          7. Miscellaneous Public Methods
          8. Protected Methods
          9. Use of Glass Pane
          10. The Metal L&F JInternalFrame.isPalette Client Property
        3. The JInternalFrame.JDesktopIcon Class
          1. Properties
          2. Constructors
          3. Methods
        4. The InternalFrameEvent Class
          1. Constants
          2. Constructor
          3. Method
        5. The InternalFrameListener Interface
          1. Methods
        6. The InternalFrameAdapter Class
          1. Methods
        7. The JDesktopPane Class
          1. Properties
          2. Constructor
          3. Methods
        8. The DesktopManager Interface
          1. Methods
        9. The DefaultDesktopManager Class
          1. Methods
          2. Protected Methods
      2. Building a Desktop
        1. Setting Things Up
        2. Veto Power
          1. Bounding the Frames
    11. 10. Swing Dialogs
      1. The JDialog Class
        1. Properties
        2. Constructors
        3. Protected Fields
        4. Public Methods
        5. Protected Methods
      2. The JOptionPane Class
        1. Properties
        2. JOptionPane Structure
        3. Using JOptionPane
        4. Events
        5. Constants
        6. Protected Fields
        7. Four Dialog Types
        8. Constructors
        9. Static Dialog Display Methods
        10. Dialog Creation Method Parameters
        11. Simple Examples
        12. Getting the Results
        13. A Comparison: Constructors vs. Static Methods
        14. Non-Static Methods
        15. Miscellaneous Static Methods
        16. Using Internal Frame Dialogs with JDesktopPane
    12. 11. Specialty Panes and Layout Managers
      1. The JSplitPane Class
        1. Properties
        2. Constants
        3. Fields
        4. Constructors
        5. Control Methods
        6. UI Methods
        7. Minimum and Preferred Sizes
      2. The JScrollPane Class
        1. Properties
        2. Fields
        3. Constructors
        4. Pane Component Methods
        5. UI Methods
        6. Headers and Corners
        7. The Scrollable Interface
          1. Increment Methods
          2. Viewport Dimension Methods
          3. The JScrollPane.ScrollBar Class
        8. ScrollPaneLayout
          1. Properties
          2. Fields
          3. Inner Classes
        9. JViewport
          1. Properties
          2. Events
          3. Fields
          4. Constructors
          5. Helper Methods
          6. Miscellaneous Methods
        10. The ViewportLayout Class
          1. Layout Methods
      3. The JTabbedPane Class
        1. Properties
        2. Events
        3. Fields
        4. Constructors
        5. Tab Methods
        6. Miscellaneous Methods
        7. UI Methods
      4. Layout Managers
        1. The Box and BoxLayout Classes
        2. The Box Class
          1. Properties
          2. Constructors
          3. Creation Methods
          4. Spacing and Resizing Methods
        3. The Box.Filler Class
          1. Properties
          2. Constructors
          3. Shape Methods
        4. The BoxLayout Class
          1. Constants
          2. Constructors
          3. Methods
        5. OverlayLayout
          1. Constructor
          2. LayoutManager2 Methods
        6. The SizeRequirements Class
          1. Fields
          2. Constructors
          3. Methods
        7. An OverlayLayout Example
      5. Other Panes
    13. 12. Chooser Dialogs
      1. The JFileChooser Class
        1. Properties
        2. Events
        3. Constants
        4. Constructors
        5. FileFilter Methods
        6. File Methods
        7. Dialog Methods
        8. Miscellaneous Methods
      2. The File Chooser Package
        1. The FileFilter Class
          1. Constructors
          2. Filter Methods
        2. The FileView Class
          1. Constructor
          2. Methods
        3. The FileSystemView Class
          1. Constructor
          2. Class Method
          3. File and Folder Methods
      3. The Color Chooser
        1. The ColorSelectionModel Interface
          1. Property
          2. Events
        2. The DefaultColorSelectionModel Class
          1. Property
          2. Events
          3. Fields
          4. Constructors
      4. The JColorChooser Class
        1. Properties
        2. Events (Inherited from JComponent)
        3. Constants
        4. Constructors
        5. Dialog Methods
        6. Chooser Panel Methods
        7. UI Methods
        8. The AbstractColorChooserPanel Class
          1. Properties
          2. Protected Helper Method
          3. Chooser Panel Methods
        9. The ColorChooserComponentFactory Class
          1. Methods
        10. Developing a Custom Chooser Panel
        11. Custom Preview Panel
        12. Developing a Custom Dialog
    14. 13. Borders
      1. Introducing Borders
        1. The Border Interface
          1. Methods
        2. Painting Borders Correctly
        3. The AbstractBorder Class
          1. Constructor
          2. Methods
      2. Swing Borders
        1. The BevelBorder and SoftBevelBorder Classes
          1. Constants
          2. Protected Fields
          3. Constructors
          4. Methods
          5. Miscellaneous
          6. Changing Borders on the Fly
        2. The Empty Border Class
          1. Property
          2. Protected Fields
          3. Constructors
          4. Method
        3. The EtchedBorder Class
          1. Properties
          2. Constants
          3. Protected Fields
          4. Constructors
          5. Miscellaneous
        4. The LineBorder Class
          1. Protected Fields
          2. Constructors
          3. Methods
          4. Miscellaneous
        5. The MatteBorder Class
          1. Property
          2. Fields
          3. Constructors
          4. Method
          5. Both Kinds of Matte Border
        6. The TitledBorder Class
          1. Properties
          2. Constants
          3. Protected Fields
          4. Constructors
          5. Miscellaneous
          6. Using a Titled Border
      3. The CompoundBorder Class
        1. Properties
        2. Constructors
        3. Miscellaneous
        4. The BorderFactory Class
          1. Methods
      4. Creating Your Own Border
    15. 14. Menus and Toolbars
      1. Introducing Swing Menus
        1. Menu Hierarchy
        2. Getting Your Feet Wet
      2. Menu Bar Selection Models
        1. The SingleSelectionModel Interface
          1. Properties
          2. Events
          3. Methods
        2. The DefaultSingleSelectionModel Class
          1. Properties
          2. Events
          3. Protected Fields
          4. Method
      3. The JMenuBar Class
        1. Menubar Placement
        2. Properties
        3. Constructor
        4. Menus
        5. Miscellaneous
        6. Menu Element Interface
      4. The JMenuItem Class
        1. Menu Item Shortcuts
        2. Images
        3. Event Handling
          1. Properties
          2. Constructors
          3. Events
          4. Methods
          5. Menu Element Interface
        4. The MenuDragMouseEvent Class
          1. Constructor
        5. The MenuDragMouseListener Interface
          1. Methods
        6. The MenuKeyEvent Class
          1. Constructor
        7. The MenuKeyListener Interface
          1. Methods
      5. The JPopupMenu Class
        1. Displaying the Popup Menu
          1. Properties
          2. Events
          3. Constructor
          4. Menu Items
          5. Display
          6. Miscellaneous
          7. Menu Element Interface
        2. Using Popup Menus
        3. The PopupMenuEvent Class
          1. Constructor
        4. The PopupMenuListener Class
          1. Methods
      6. The JMenu Class
        1. Properties
        2. Constructor
        3. Menu Items
        4. Miscellaneous
        5. Events
        6. Menu Element Interface
        7. Working with Menus
        8. The MenuEvent Class
          1. Constructor
        9. The MenuListener Interface
          1. Methods
      7. Selectable Menu Items
        1. The JCheckBoxMenuItem Class
          1. Properties
          2. Constructors
          3. Miscellaneous
          4. Using Checkbox Menu Items
        2. The JRadioButtonMenuItem Class
          1. Properties
          2. Constructors
          3. Miscellaneous
          4. Enforcing Mutual Exclusion
        3. The JSeparator Class
          1. Properties
          2. Constructor
          3. Miscellaneous
          4. Using a Separator Outside of a Menu
        4. The MenuElement Interface
          1. Making arbitrary components into menu elements
      8. Toolbars
        1. The JToolBar Class
          1. Floating Toolbars
          2. Properties
          3. Events
          4. Constructors
          5. Adding Actions
          6. Miscellaneous
          7. Creating a Toolbar
          8. The MetalToolBarUI isRollover property
    16. 15. Tables
      1. Table Columns
        1. The TableColumn Class
          1. Properties
          2. Constants
          3. Events
          4. Fields
          5. Constructors
          6. Miscellaneous Methods
        2. The TableColumnModel Interface
          1. Properties
          2. Events
          3. Column Methods
        3. The DefaultTableColumnModel Class
          1. Properties
          2. Events
          3. Fields
          4. Constructors
          5. Methods
        4. The TableColumnModelEvent Class
          1. Fields
          2. Constructors
          3. Event Methods
        5. The TableColumnModelListener Interface
        6. Implementing A Column Model
      2. Table Data
        1. The TableModel Interface
          1. Properties
          2. Events
          3. Cell Methods
        2. The AbstractTableModel Class
          1. Fields
          2. Events
          3. TableModel Methods
        3. The TableModelEvent Class
          1. Constants
          2. Fields
          3. Constructors
        4. The TableModelListener Interface
        5. The DefaultTableModel Class
          1. Properties
          2. Events
          3. Fields
          4. Constructors
          5. Data Methods
          6. Row and Column Methods
        6. Dynamic Table Data
        7. Database Data
      3. The JTable Class
        1. Properties
        2. Events
        3. Constants
        4. Fields
        5. Constructors
        6. Protected Initialization and Helper Methods
        7. Editor and Renderer Methods
        8. Selection Methods
        9. Row and Column Methods
        10. Cell Methods
        11. Event Listener Support Methods
        12. Miscellaneous Methods
        13. The JTableHeader Class
          1. Properties
          2. Fields
          3. Constructors
          4. Column Methods
          5. Miscellaneous Methods
          6. Tooltip and UI Methods
      4. Editing and Rendering
        1. The TableCellRenderer Interface
        2. The DefaultTableCellRenderer Class
          1. Properties
          2. Protected Constants
          3. Constructors
          4. Inner Classes
          5. Renderer Methods
        3. The TableCellEditor Interface
      5. Selecting Table Entries
    17. 16. Advanced Table Examples
      1. A Table with Row Headers
      2. Large Tables with Paging
      3. Charting Data with a TableModel
    18. 17. Trees
      1. A Simple Tree
        1. Tree Terminology
      2. Tree Models
        1. The TreeModel Interface
          1. Property
          2. Events
          3. Miscellaneous Methods
        2. The DefaultTreeModel Class
          1. Properties
          2. Events
          3. Fields
          4. Constructors
          5. Miscellaneous Methods
        3. Working with Tree Models
      3. Tree Nodes and Paths
        1. The TreeNode Interface
          1. Properties
          2. Child Access Methods
        2. The MutableTreeNode Interface
          1. Properties
          2. Mutation Methods
        3. The DefaultMutableTreeNode Class
          1. Properties
          2. Constant
          3. Fields
          4. Constructors
          5. Structure Methods
          6. Enumeration Methods
          7. Miscellaneous Methods
        4. The TreePath Class
          1. Properties
          2. Fields
          3. Constructors
          4. Miscellaneous Methods
      4. The JTree Class
        1. Properties
        2. Events
        3. Constants
        4. Fields
        5. Constructors
        6. Tree Model Methods
        7. Selection Methods
        8. Expansion Methods
        9. Path and Row Methods
        10. Editing Methods
        11. Miscellaneous Methods
        12. JTree Inner Classes
        13. UI Methods
      5. Tree Selections
        1. The RowMapper Interface
        2. The TreeSelectionModel Interface
          1. Properties
          2. Constants
          3. Events
          4. Selection Methods
        3. The DefaultTreeSelectionModel Class
          1. Properties
          2. Events
          3. Constant
          4. Fields
          5. Constructors
          6. Additional Methods
      6. Tree Events
        1. The TreeModelEvent Class
          1. Fields
          2. Constructors
          3. Methods
        2. The TreeModelListener Interface
        3. The TreeSelectionEvent Class
          1. Fields
          2. Constructors
          3. Methods
        4. The TreeSelectionListener Interface
        5. The TreeExpansionEvent Class
          1. Fields
          2. Constructors
          3. Methods
        6. The TreeExpansionListener Interface
        7. Pending Expansion Events
          1. The TreeWillExpandListener Interface
          2. The ExpandVetoException Class
          3. Constructors
          4. Fields
        8. Implementing the Expansion Listener Interface
      7. Rendering and Editing
        1. Rendering Nodes
          1. But I only want to change the icons!
        2. The DefaultTreeCellRenderer Class
          1. Properties
          2. Constructors
          3. Fields
          4. Rendering Methods
        3. Custom Renderers
        4. The TreeCellRenderer Interface
        5. Editing Nodes
        6. The TreeCellEditor Interface
        7. The DefaultTreeCellEditor Class
          1. Properties
          2. Events
          3. Fields
          4. Constructors
          5. Event Methods
          6. CellEditor and TreeCellEditor Methods
          7. Helper Methods
          8. Inner Classes
        8. Look-and-Feel Helper Classes
      8. What Next?
    19. 18. Undo
      1. The Swing Undo Facility
        1. The UndoableEdit Interface
          1. Properties
          2. Edit Merging Methods
          3. Other Methods
        2. The AbstractUndoableEdit Class
          1. Properties
          2. Constants
          3. Constructors
          4. UndoableEdit Methods
          5. Other Methods
          6. Creating a Toggle Edit
        3. The CompoundEdit Class
          1. Properties
          2. Protected Fields
          3. Constructors
          4. UndoableEdit Methods
          5. Other Methods
          6. Using Compound Edits
        4. The UndoableEditEvent Class
          1. Property
          2. Constructors
        5. The UndoableEditListener Interface
          1. Methods
        6. The UndoManager Class
          1. A Codeless Example
          2. Transformer?
          3. Properties
          4. Constructor
          5. UndoableEditListener Method
          6. UndoableEdit Methods
          7. New Public Methods
          8. Protected Methods
          9. Other Methods
          10. Using an Undo Manager
          11. Understanding the UndoManager in-depth
          12. Extending UndoManager
        7. The StateEditable Interface
          1. Methods
        8. The StateEdit Class
          1. State Optimization
          2. Property
          3. Protected Fields
          4. Constructors
          5. UndoableEdit Methods
          6. New Public Methods
          7. Protected Methods
          8. StateEdit Example
        9. The UndoableEditSupport Class
          1. Property
          2. Protected Fields
          3. Constructors
          4. UndoableEditEvent/Listener Support Methods
          5. Nested Edit Support
          6. Other Methods
          7. Using Undoable Edit Support
        10. The CannotRedoException Class
        11. The CannotUndoException Class
        12. Extending UndoManager
    20. 19. Text 101
      1. The Swing Text Components
        1. The JTextComponent Class
          1. Properties
          2. Events
          3. Constants
          4. Constructors
          5. Clipboard Methods
          6. Selection Methods
          7. View Methods
          8. Working with Keymaps
          9. Other Methods
        2. The JTextComponent.KeyBinding Class
          1. Fields
          2. Constructors
        3. The JTextField Class
          1. Properties
          2. Events
          3. Constants
          4. Constructors
          5. Public Methods
          6. Protected Methods
          7. A Simple Form
          8. Understanding JTextField Sizing
          9. Restricting Input
        4. The JPasswordField Class
          1. Properties
          2. Constructors
          3. Data Protection Methods
          4. Miscellaneous Methods
        5. The JTextArea Class
          1. Properties
          2. Events
          3. Constructors
          4. Text Manipulation Methods
          5. Line Transformation Methods
          6. Protected Methods
          7. Understanding JTextArea Sizing
        6. The JEditorPane Class
          1. Properties
          2. Events
          3. Constructors
          4. EditorKit Methods
          5. Miscellaneous Methods
        7. The HyperlinkListener Interface
        8. The HyperlinkEvent Class
          1. Properties
          2. Constructors
          3. Inner Classes
        9. The JTextPane Class
          1. Using the JTextPane
      2. More to Come
    21. 20. Document Model and Events
      1. The Document Model
        1. The Document Interface
          1. Properties
          2. Events
          3. Constants
          4. Text Manipulation Methods
          5. Other Methods
        2. The Element Interface
          1. Properties
          2. Miscellaneous Method
        3. The ElementIterator Class
          1. Constructors
          2. Methods
        4. The AttributeSet Interface
          1. Properties
          2. Methods
          3. Inner Interfaces
        5. The MutableAttributeSet Interface
          1. Properties
          2. Methods
        6. The SimpleAttributeSet Class
          1. Properties
          2. Constant
          3. Constructors
          4. Add/Remove Methods
          5. Query Methods
          6. Miscellaneous Methods
          7. Using a Resolving Parent
        7. The Position Interface
          1. Property
          2. An Example
        8. The Position.Bias Class
          1. Constants
          2. Methods
        9. The Segment Class
          1. Fields
          2. Constructors
          3. Methods
        10. The AbstractDocument Class
          1. Properties
          2. Events
          3. Constants
          4. Field
          5. Constructors
          6. Locking
          7. Reading and Writing
          8. Other Public Methods
          9. Other Protected Methods
          10. Document Locking Example
        11. The AbstractDocument.AbstractElement Class
          1. Properties
          2. Constructors
          3. AttributeSet Methods
          4. MutableAttributeSet Methods
          5. TreeNode Methods
          6. Other Methods
        12. The AbstractDocument.LeafElement Class
          1. Properties
          2. Constructor
          3. Methods
        13. The AbstractDocument.BranchElement Class
          1. Properties
          2. Constructor
          3. Methods
        14. The AbstractDocument.Content Interface
          1. Methods
        15. The StringContent Class
          1. Constructors
          2. Public Methods
          3. Protected Methods
        16. The GapContent Class
          1. Constructors
          2. AbstractDocument.Content Methods
        17. The AbstractDocument.AttributeContext Interface
          1. Property
          2. Attribute Management
        18. The BadLocationException Class
          1. Constructor
          2. Methods
        19. Model Summary So Far
        20. The PlainDocument Class
          1. Property
          2. Constants
          3. Constructors
          4. Protected Methods
          5. Looking at PlainDocument’s Element Structures
          6. Filtering JTextFields
      2. Document Events
        1. The DocumentEvent Interface
          1. Properties
          2. Change Details
        2. The DocumentEvent.EventType Class
          1. Method
        3. The DocumentEvent.ElementChange Interface
          1. Properties
        4. The DocumentListener Interface
          1. Methods
        5. Document and Undo Event Example
      3. Advanced AbstractDocument Event Model
        1. The AbstractDocument.ElementEdit Class
          1. Properties
          2. Constructor
          3. UndoableEdit Methods
        2. The AbstractDocument.DefaultDocumentEvent Class
          1. Properties
          2. Constructor
          3. UndoableEdit Methods
          4. DocumentEvent Method
          5. Other Method
    22. 21. Styled Documents and JTextPane
      1. Style
        1. The Style Interface
          1. Property
          2. Events
        2. The StyleConstants Class
          1. StyleConstants Inner Classes
          2. Attribute Constants
          3. Other Attribute Constants
          4. Alignment Value Constants
          5. Element Name Constants
          6. Lookup and Update Methods
        3. The TabStop Class
          1. Properties
          2. Alignment Constants
          3. Leader Constants
          4. Constructors
          5. Object Methods
        4. The TabSet Class
          1. Properties
          2. Constructor
          3. Methods
        5. The StyleContext Class
          1. Properties
          2. Events
          3. Constants
          4. Constructor
          5. AttributeContext Methods
          6. A Look Inside
          7. Style Management Methods
          8. Font Management Methods
          9. Color Accessor Methods
          10. Serialization Methods
          11. Other Methods
        6. The StyledContext.NamedStyle Class
          1. Properties
          2. Events
          3. Fields
          4. Constructors
          5. AttributeSet Methods
          6. MutableAttributeSet Methods
          7. Other Method
        7. The StyledDocument Interface
          1. Properties
          2. Specific Attribute Accessors
          3. Style Management
          4. Element Query Methods
          5. AttributeSet Modification Methods
        8. The DefaultStyledDocument Class
          1. Properties
          2. Constant
          3. Constructors
          4. Specific Attribute Accessors
          5. Style Management Methods
          6. Element Query Methods
          7. Attribute Modification Methods
          8. Element Structure Methods
          9. Other Protected Methods
        9. The DefaultStyledDocument.SectionElement Class
          1. Properties
          2. Constructor
        10. The DefaultStyledDocument.ElementSpec Class
          1. Properties
          2. Direction Constants
          3. Type Constants
          4. Constructors
          5. Methods
        11. The DefaultStyledDocument.ElementBuffer Class
          1. Property
          2. Constructor
          3. Public Methods
          4. Protected Methods
        12. The JTextPane Class
          1. Properties
          2. Constructors
          3. StyledDocument Delegation Methods
          4. Attribute and Style Methods
          5. Adding Non-Text Content
          6. Other Public Method
          7. Protected Methods
      2. A Stylized Editor
    23. 22. Carets, Highlighters, and Keymaps
      1. JTextComponent UI Properties
        1. The Caret Interface
          1. Properties
          2. Events
          3. Methods
        2. The DefaultCaret Class
          1. Properties
          2. Events
          3. Fields
          4. Constructors
          5. Caret Methods
          6. FocusListener Methods
          7. Mouse Methods
          8. Protected Methods
          9. An XOR Caret
        3. The CaretListener Interface
          1. Method
        4. The CaretEvent Class
          1. Properties
          2. Constructor
        5. The Highlighter Interface
          1. Property
          2. Methods
        6. The Highlighter.Highlight Interface
          1. Properties
        7. The Highlighter.HighlightPainter Interface
          1. Method
        8. The DefaultHighlighter Class
          1. Property
          2. Constructor
          3. Methods
        9. The DefaultHighlighter.DefaultHighlightPainter Class
          1. Property
          2. Constructor
          3. Method
          4. A Custom Highlighter
        10. The Keymap Interface
          1. Properties
          2. Methods
          3. Keymap Implementation
          4. Adding Keyboard Actions
    24. 23. Text Views
      1. Text Views
        1. A Few Notes
          1. Shape vs. Rectangle
          2. Floats
          3. Span and Allocation
        2. Overview of the View Classes
          1. The “Root” View
      2. The View Classes
        1. The View Class
          1. Properties
          2. Constructor
          3. Constants
          4. Miscellaneous Public Methods
          5. Update Methods
          6. Abstract Method
        2. The ViewFactory Interface
          1. Factory Method
        3. The TabExpander Interface
          1. Methods
        4. The TabableView Interface
          1. Methods
        5. The Utilities Class
          1. Public Static Methods
        6. The PlainView Class
          1. Properties
          2. Field
          3. Constructor
          4. Document Event Methods
          5. TabExpander Method
          6. Other Public Methods
          7. Protected Drawing Methods
          8. Other Protected Methods
        7. The FieldView Class
          1. Properties
          2. Constructors
          3. Public Methods
          4. Protected Methods
        8. The PasswordView Class
          1. Properties
          2. Constructors
          3. Protected Methods
        9. The LabelView Class
          1. Properties
          2. Constructor
          3. TabableView Methods
          4. Other Public Methods
          5. Protected Methods
        10. The ComponentView Class
          1. Properties
          2. Constructor
          3. Methods
        11. The IconView Class
          1. Properties
          2. Constructors
          3. Methods
        12. The CompositeView Class
          1. Properties
          2. Constructors
          3. View Methods
          4. New Public Methods
          5. Protected Methods
          6. Abstract Protected Methods
        13. The BoxView Class
          1. Properties
          2. Constructor
          3. Document Update Methods
          4. Public Methods
          5. CompositeView Protected Methods
          6. Other Protected Methods
        14. The ParagraphView Class
          1. Properties
          2. Constructor
          3. TabExpander Methods
          4. Document Change Methods
          5. New Public Methods
          6. BoxView (and Superclasses) Methods
          7. New Protected Methods
        15. The WrappedPlainView Class
          1. Properties
          2. Constructors
          3. TabExpander Methods
          4. Document Update Methods
          5. BoxView Methods
          6. New Protected Methods
        16. The TableView Class
          1. Properties
          2. Constructor
          3. BoxView Methods
          4. New Protected Methods
        17. The TableView.TableRow Class
          1. Properties
          2. Constructor
          3. Methods
        18. The TableView.TableCell Class
          1. Properties
          2. Constructor
          3. New Methods
          4. BoxView Method
    25. 24. EditorKits and TextActions
      1. Overview of the Editor Kits
        1. The EditorKit Class
          1. Properties
          2. Constructor
          3. Abstract Methods
          4. Other Methods
        2. The TextAction Class
          1. Constructor
          2. Static Method
          3. Protected Methods
        3. The DefaultEditorKit Class
          1. Properties
          2. Constants
          3. Using Actions
          4. Constructor
          5. Methods
        4. The DefaultEditorKit.DefaultKeyTypedAction Class
          1. Constructor
          2. Method
        5. The DefaultEditorKit.BeepAction Class
          1. Constructor
          2. Method
        6. The DefaultEditorKit.CopyAction Class
          1. Constructor
          2. Method
        7. The DefaultEditorKit.CutAction Class
          1. Constructor
          2. Method
        8. The DefaultEditorKit.InsertBreakAction Class
          1. Constructor
          2. Method
        9. The DefaultEditorKit.InsertContentAction Class
          1. Constructor
          2. Method
        10. The DefaultEditorKit.InsertTabAction Class
          1. Constructor
          2. Method
        11. The DefaultEditorKit.PasteAction Class
          1. Constructor
          2. Method
        12. A Simple Text Editor
        13. The StyledEditorKit Class
          1. Properties
          2. Constructor
          3. EditorKit Methods
        14. The StyledEditorKit.StyledTextAction Class
          1. Constructor
          2. Protected Methods
        15. The StyledEditorKit.FontFamilyAction Class
          1. Constructor
          2. Method
        16. The StyledEditorKit.FontSizeAction Class
          1. Constructor
          2. Method
        17. The StyledEditorKit.ForegroundAction Class
          1. Constructor
          2. Method
        18. The StyledEditorKit.AlignmentAction Class
          1. Constructor
          2. Method
        19. The StyledEditorKit.BoldAction Class
          1. Constructor
          2. Method
        20. The StyledEditorKit.ItalicAction Class
          1. Constructor
          2. Method
        21. The StyledEditorKit.UnderlineAction Class
          1. Constructor
          2. Method
        22. A Better Editor
          1. Saving Styled Documents
        23. The HTML Package
          1. Parsing HTML
          2. Representing HTML
          3. Displaying HTML
          4. Writing HTML
        24. Much, Much More
        25. RTFEditorKit
          1. Property
          2. Constructor
          3. Methods
          4. Generating RTF Output
        26. The AbstractWriter Class
          1. Constant
          2. Constructors
          3. Abstract Method
          4. Output Generating Methods
          5. Other Methods
          6. Implementing AbstractWriter
        27. Building Your Own EditorKit
          1. Create the EditorKit Class
          2. Define the Document Type
          3. Define New Actions
          4. Create Custom View Classes
          5. Create a ViewFactory and View Classes
          6. Create a “Reader” and a “Writer”
          7. Tell JEditorPane about Your New Kit
      2. Phew!
    26. 25. Programming with Accessibility
      1. How Accessibility Works
        1. JDK 1.2 Accessibility
        2. The Accessibility Contract
        3. How Do I Get It?
          1. Swing
          2. AWT
      2. The Accessibility Package
        1. The Path to Determining Accessibility
        2. The Accessible Interface
          1. Method
        3. The AccessibleContext Class
          1. Properties
          2. Accessible Names and Descriptions
          3. Constructor
          4. Events
          5. Constants
      3. Other Accessible Objects
        1. AccessibleState
          1. Constructor
        2. AccessibleStateSet
          1. Field
          2. Constructors
          3. Methods
        3. AccessibleRole
          1. Constructor
      4. The Six Types of Accessibility
        1. The AccessibleAction Interface
          1. Properties
          2. Method
        2. The AccessibleComponent Interface
          1. Properties
          2. Methods
          3. Events
        3. The AccessibleSelection Interface
          1. Properties
          2. Methods
        4. The AccessibleText Interface
          1. Properties
          2. Constants
          3. Methods
        5. The AccessibleHypertext Interface
          1. Properties
        6. The AccessibleHyperlink Class
          1. Properties
          2. Method
        7. The AccessibleValue Interface
          1. Methods
        8. Implementing AccessibleAction
      5. The Accessibility Utility Classes
        1. The EventQueueMonitor Class
          1. Constructor
          2. Initialization
          3. Methods
        2. The AWTEventMonitor Class
          1. Fields
          2. Constructor
          3. Methods
        3. The SwingEventMonitor Class
          1. Fields
          2. Constructor
          3. Methods
        4. The TopLevelWindowListener Interface
          1. Methods
        5. The GUIInitializedListener Interface
          1. Method
      6. Interfacing with Accessibility
    27. 26. Look & Feel
      1. How Does It Work?
      2. Key L&F Classes and Interfaces
        1. The LookAndFeel Class
          1. Properties
          2. Constructor
          3. Methods
          4. Static Convenience Methods
        2. The UIDefaults Class
          1. Events
          2. Constructors
          3. Methods
        3. The UIDefaults.ActiveValue Interface
          1. Method
          2. Creating an ActiveValue
        4. The UIDefaults.LazyValue Interface
          1. Method
          2. Creating a LazyValue
        5. The UIResource Interface
          1. Static BorderUIResource Methods
          2. BorderUIResource Inner Classes
        6. The UIManager Class
          1. LAFState
          2. UIManager L&F Concepts
          3. Look-and-Feel Properties File
          4. Events
          5. UIDefaults Convenience Methods
          6. Other Static Methods
          7. Changing the Look-and-Feel
          8. Managing Defaults
        7. The UIManager.LookAndFeelInfo Class
          1. Properties
          2. Constructor
          3. Method
        8. The ComponentUI Class
          1. Methods
          2. Static Method
      3. The MultiLookAndFeel
        1. Creating an Auxilliary Look-and-Feel
        2. Installing the MultiLookAndFeel
      4. Look-and-Feel Customization
        1. Modification of Component Properties
        2. Modification of the UI Defaults
          1. Making Global Changes with Defaults
        3. Use of Metal’s Themes
          1. MetalTheme Properties
          2. Abstract Protected Methods
          3. Black and White
          4. Additional Customization
          5. DefaultMetalTheme Font Properties
          6. Protected DefaultMetalTheme Base Colors
        4. Use of Metal’s Client Properties
        5. Replacement of Individual UI Delegates
          1. Modifying a Scrollbar
      5. Creation of a Custom L&F
        1. The PlainLookAndFeel
        2. Creating the LookAndFeel Class
          1. Defining Class Defaults
          2. Defining L&F Colors
          3. Defining Component Defaults
        3. Defining an Icon Factory
        4. Defining Custom Borders
        5. The BasicGraphicsUtils Class
          1. Methods
        6. Create the Individual UI Delegates
          1. Define a Constructor
          2. Define the Factory Method
          3. Define installUI() and uninstallUI() (optional)
          4. Define Component Size
          5. Override Component-Specific Details
          6. Paint the Component
        7. Don’t Forget to Use It
        8. How’s It Look?
        9. One Down...
    28. 27. Swing Utilities
      1. General Utilities
        1. The SwingUtilities Class
          1. Constructor
          2. Class Methods
        2. The SwingConstants Interface
        3. The Timer Class
          1. Properties
          2. Events
          3. Fields
          4. Constructor
          5. Timer Control Methods
        4. The ToolTipManager Class
          1. Properties
          2. Fields
          3. Mouse Event Methods
          4. Miscellaneous Methods
        5. The JToolTip Class
          1. Properties
          2. Constructor
          3. UI Method
      2. Editing and Rendering Utilities
        1. The CellRendererPane Class
          1. Property
          2. Field
          3. Constructor
          4. Methods
          5. Inner Classes
        2. The CellEditor Interface
          1. Events
          2. Methods
        3. The CellEditorListener Interface
        4. The DefaultCellEditor Class
          1. Properties
          2. Events
          3. Constructors
          4. Fields
          5. Tree and Table Editor Methods
      3. Event Utilities
        1. The EventListenerList Class
          1. Field
          2. Constructor
          3. Listener Methods
        2. The KeyStroke Class
          1. Properties
          2. Key Codes
          3. Instantiation Methods
          4. Overriden Object Methods
        3. The MouseInputAdapter Class
          1. Methods
          2. The SwingPropertyChangeSupport Class
          3. Constructor
          4. Methods
      4. Image Utilities
        1. The GrayFilter Class
          1. Constructors
          2. Image Methods
        2. The Renderer Interface
    29. 28. Swing Under the Hood
      1. Creating Your Own Component
        1. Creating the Component
          1. You Should Have a Model and a UI Delegate
        2. Creating a Model
          1. Reuse or Extend Existing Models Whenever Possible
          2. Decide on Properties and Create the Model Interface
          3. Send Events When Bound Properties Change
          4. Reuse the EventListenerList Class
          5. Don’t Put Component Properties in the Model
          6. Implement the Model
        3. The UI Delegate
          1. Create an Abstract Type Class
          2. You Must Implement a Paint Method
          3. Be Able To Resize Yourself
        4. Creating the Component Itself
          1. Decide on Properties
          2. Listen to Your Models
          3. Send Events When Bound Properties Change
        5. Some Final Questions
        6. The Jog Shuttle: A Simple Swing Component
          1. The Component
          2. The UI Delegate
        7. A Toy Using the Shuttle
      2. Working with Focus
        1. Focus Cycle Root
        2. Managing Focus
        3. Focus Traversable
        4. Request Focus Enabled
        5. Next Focusable Component
        6. Using the Focus Properties
        7. The FocusManager Class
          1. Constant
          2. Constructor
          3. Methods
        8. The DefaultFocusManager Class
          1. Constructor
          2. Methods
          3. Writing Your Own Focus Manager
      3. Lightweight vs. Heavyweight Components
        1. Understanding the Z-Order
        2. Mixing Swing and AWT
          1. Overlapping Heavyweight and Lightweight Components
          2. Heavyweight Components in Front of Lightweight Menus
          3. Popups
          4. Heavyweight Components in JScrollPane
          5. Heavyweight Components Inside of Internal Frames
      4. Multithreading Issues with Swing
        1. When Is Thread Safety an Issue?
          1. Don’t Be Fooled
        2. Updating Components in the Event Dispatch Thread
          1. Methods
          2. Managing Synchronization Properly
      5. Painting and Repainting
        1. Swing Responsibilities
        2. The RepaintManager Class
          1. Key Methods
          2. Methods
    30. A. Look & Feel Resources
    31. Index
    32. Colophon