<<

APPENDIX A UI Manager Properties

THROUGHOUT THIS BOOK YOU'LL FIND TABLES that list the property names and data types for all the UIResource elements of specific components. Although these tables serve to list all the information about a specific component, I fig• ured it would be handy to also group all the information about property names in one place. With that in mind, Table A-1 provides a complete list of properties used by the predefined classes-Motif, , Metal, and Windows• provided with the Swing 1.1.1 release. The table indicates with an "X" which of the four look and feel classes uses a particular property. To change the default setting for any one of these properties, you need to notify the UIManager by storing a new setting in the lookup table of the UIManager. For instance, to change the default text for the "Yes" on a JOptionPane,

11 you'd replace the 0ptionPane. yesButtonText II property with the new setting

11 11 UIManager. put ( 0ptionPane. yesButtonTextll, Si II);. Then, any component cre• ated after the setting change will get the new value: 11 5i 11 .1fyou want a displayed component to get the new setting, you must call its updateUI () method. When you change the current look and feel, any custom settings you install may be lost. If the class of the property value setting implements the UIResource interface (an empty marker interface such as Serializable), then the setting will be replaced by the default setting of the look and feel. For example, the first set• ting that follows would be saved when the look and feel changes; the second would not.

11 UIManager.put( 11 0ptionPane.background , Color.red); versus

11 11 UIManager.put( 0ptionPane.background , new ColorUIResource(Color.red));

If the property value setting does not implement the UIResource interface, then the property setting is retained when the look and feel changes.

807 Appendix A

WARNING A word ofcaution about the information in Table A-1: The specific set of available properties changes with each ]PC!Project Swing release. This table reflects the current settings for release 1.1.1. Some properties may not be in earlier versions, and others may have been replaced in later versions. The changes tend to be minor, but they do exist. For a resource that lists the specific properties available with each release, see the Swing PLAF Differences list at http://www.gargoylesoftware.com/ papers/plafdiff. html from Gargoyle .

...... ··········· ····· PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS activeCaption Color X X X X activeCaptionBorder Co lot X X X X activeCaptionText Color X X X X Button. background Color X X X X Button. border Border X X X X Button.dashedRectGapHeight Integer X Button.dashedRectGapWidth Integer X Button.dashedRectGapX Integer X Button.dashedRectGapY Integer X Button.disabledText Color X X Button.focus Color X X Button.font Font X X X X Button.foreground Color X X X X Button.margin Insets X X X X Button.select Color X X X Button.selectText Color X Button.textlconGap Integer X X X X Button. textShiftOffset Integer X X X X ButtonUI String X X X X . background Color X X X X CheckBox. border Border X X X X CheckBox.darkShadow Color X CheckBox.disabledText Color X X CheckBox.focus Color X X X CheckBox.font Font X X X X CheckBox.foreground Color X X X X CheckBox. highlight Color X CheckBox. Icon X X X X CheckBox. margin Insets X X X X Checkbox. select Color X

(continued)

808 UI Manager Properties

TableA-1 (continued)

······················ ····················· ...... ······················ ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS CheckBox. shadow Color X CheckBox.textlconGap Integer X X X X CheckBox. textShiftOffset Integer X X X X CheckBoxMenultem.acceleratorFont Font X X X X CheckBoxMenultem.acceleratorForeground Color X X X X CheckBoxMenultem.acceleratorSelectionForeground Color X X X X CheckBoxMenultem.arrowlcon Icon X X X X CheckBoxMenultem.background Color X X X X CheckBoxMenultem.border Border X X X X CheckBoxMenultem.borderPainted Boolean X X X X CheckBoxMenultem.checklcon Icon X X X X CheckBoxMenultem.disabledForeground Color X X CheckBoxMenultem.font Font X X X X CheckBoxMenultem.foreground Color X X X X CheckBoxMenultem.margin Insets X X X X CheckBoxMenultem.selectionBackground Color X X X X CheckBoxMenultem.selectionForeground Color X X X X CheckBoxMenultemUI String X X X X CheckBoxUI String X X X X ColorChooser.background Color X X X X ColorChooser.cancelText String X X X X ColorChooser.font Font X X X X ColorChooser.foreground Color X X X X ColorChooser.hsbBlueText String X X X X ColorChooser.hsbBrightnessText String X X X X ColorChooser.hsbGreenText String X X X X ColorChooser.hsbHueText String X X X X ColorChooser.hsbNameText String X X X X ColorChooser.hsbRedText String X X X X ColorChooser.hsbSaturationText String X X X X ColorChooser.okText String X X X X ColorChooser.previewText String X X X X ColorChooser.resetText String X X X X ColorChooser.rgbBlueMnemonic Integer X X X X ColorChooser.rgbBlueText String X X X X ColorChooser.rgbGreenMnemonic Integer X X X X ColorChooser.rgbGreenText String X X X X ColorChooser.rgbNameText String X X X X ColorChooser.rgbRedMnemonic Integer X X X X

(continued)

809 Appendix A

TableA-1 (continued)

...... ····································································· ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS ColorChooser.rgbRedText String X X X X ColorChooser.swatchesDefaultRecentColor Color X X X X ColorChooser.swatchesNameText String X X X X ColorChooser.swatchesRecentSwatchSize Dimension X X X X ColorChooser.swatchesRecentText String X X X X ColorChooser.swatchesSwatchSize Dimension X X X X ColorChooserUI String X X X X ComboBox.background Color X X X X ComboBox.border Border X X ComboBox.control Color X ComboBox.controlForeground Color X ComboBox.disabledBackground Color X X X X ComboBox.disabledForeground Color X X X X ComboBox.font Font X X X X ComboBox.foreground Color X X X X ComboBox.listBackground Color X X ComboBox.listForeground Color X X ComboBox.selectionBackground Color X X X X ComboBox.selectionForeground Color X X X X ComboBoxUI String X X X X control Color X X X X controlDkShadow Color X X X X controlHighlight Color X X X X controlLightShadow Color X controlLtHighlight Color X X X X controlShadow Color X X X X controlText Color X X X X desktop Color X X X X Desktop. background Color X X X X Desktoplcon.background Color X Desktoplcon.border Border X X X Desktoplcon.font Font X Desktoplcon.foreground Color X Desktoplcon.icon Icon X DesktoplconUI String X X X X DesktopPaneUI String X X X X DirectoryPaneUI String X EditorPane.background Color X X X X EditorPane. border Border X X X X

(continued)

810 UI Manager Properties

TableA-1 (continued) ...... ································································ PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS EditorPane.caretBlinkRate Integer X X X X EditorPane.caretForeground Color X X X X EditorPane.font Font X X X X EditorPane.foreground Color X X X X EditorPane.inactiveForeground Color X X X X EditorPane.keyBindings KeyBinding[ ] X X X X EditorPane.margin Insets X X X X EditorPane.selectionBackground Color X X X X EditorPane.selectionForeground Color X X X X EditorPaneUI String X X X X FileChooser.acceptAllFileFilterText String X X X X FileChooser.cancelButtonMnemonic Integer X X X X FileChooser.cancelButtonText String X X X X FileChooser.cancelButtonToolTipText String X X X X FileChooser.detailsViewButtonAccessibleName String X X FileChooser.detailsViewButtonToolTipText String X X FileChooser.detailsViewlcon Icon X X X X FileChooser.directoryDescriptionText String X X X X FileChooser.enterFileNameLabelMnemonic Integer X FileChooser.enterFileNameLabelText String X FileChooser.fileDescriptionText String X X X X FileChooser.fileNameLabelMnemonic Integer X X FileChooser.fileNameLabelText String X X FileChooser.filesLabelMnemonic Integer X FileChooser.filesLabelText String X FileChooser.filesOfl'ypeLabelMnemonic Integer X X FileChooser.filesOfl'ypeLabelText String X X FileChooser.filterLabelMnemonic Integer X FileChooser.filterLabelText String X FileChooser.foldersLabelMnemonic Integer X FileChooser.foldersLabelText String X FileChooser.helpButtonMnemonic Integer X X X X FileChooser.helpButtonText String X X X X FileChooser.helpButtonToolTipText String X X X X FileChooser.homeFolderAccessibleName String X X FileChooser.homeFolderlcon Icon X X X X FileChooser.homeFolderToolTipText String X X FileChooser.listViewButtonAccessibleName String X X FileChooser.listViewButtonToolTipText String X X

(continued)

811 Appendix A

TableA-1 (continued) ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS FileChooser.listViewlcon Icon X X X X FileChooser.looklnLabelMnemonic Integer X X FileChooser.looklnLabelText String X X FileChooser.newFolderAccessibleName String X X FileChooser.newFolderErrorSeparator String X X X X FileChooser.newFolderErrorText String X X X X FileChooser.newFolderlcon Icon X X X X FileChooser.newFolderToolTipText String X X FileChooser.openButtonMnemonic Integer X X X X FileChooser.openButtonText String X X X X FileChooser.openButtonToolTipText String X X X X FileChooser.pathLabelMnemonic Integer X FileChooser. pathLabelText String X FileChooser.saveButtonMnemonic Integer X X X X FileChooser.saveButtonText String X X X X FileChooser.saveButtonToolTipText String X X X X FileChooser.updateButtonMnemonic Integer X X X X FileChooser.updateButtonText String X X X X FileChooser.updateButtonToolTipText String X X X X FileChooser.upFolderAccessibleName String X X FileChooser.upFolderlcon Icon X X X X FileChooser. upFolderToolTipText String X X FileChooserUI String X X X X FileView.computerlcon Icon X X X X FileView.directorylcon Icon X X X X FileView.filelcon Icon X X X X FileView.floppyDrivelcon Icon X X X X FileView.hardDrivelcon Icon X X X X FocusManagerClassName String X X X X inactiveCaption Color X X X X inactiveCaptionBorder Color X X X X inactiveCaptionText Color X X X X info Color X X X X info Text Color X X X X lnternalFrame.activeTitleBackground Color X X X X InternalFrame.activeTitleForeground Color X X X X InternalFrame.border Border X X X X InternalFrame.closelcon Icon X X X X InternalFrame.closePressed Icon X

(continued)

812 UI Manager Properties

TableA-1 (continued) ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS InternalFrame.font Font X X InternalFrame.icon Icon X X X InternalFrame.iconifyicon Icon X X X X InternalFrame.iconifyPressed Icon X InternalFrame.iconizelcon Icon X InternalFrame.inactiveTitleBackground Color X X X X InternalFrame.inactiveTitleForeground Color X X X X InternalFrame.maxirnizelcon Icon X X X X InternalFrame.maximizePressed Icon X InternalFrame.rninirnizelcon Icon X X X X InternalFrame.rninirnizeiconBackground Color X InternalFrame. paletteBorder Border X InternalFrame. paletteCloselcon Icon X InternalFrame. paletteTitleHeight Integer X InternalFrame. titleFont Font X X X X InternalFrame.windowShadeBorder Border X InternalFrameUI String X X X X . background Color X X X X Label.disabledForeground Color X X X X Label.disabledShadow Color X X X X Label.font Font X X X X Label.foreground Color X X X X LabelUI String X X X X List. background Color X X X X List. border Border X X X X List.cellRenderer ListCellRender X X X X List.focusCellHighlightBorder Border X X X X List.font Font X X X X List.foreground Color X X X X List.selectionBackground Color X X X X List.selectionForeground Color X X X X ListUI String X X X X Color X X X X Menu.acceleratorFont Font X X X X Menu.acceleratorForeground Color X X X X Menu.acceleratorPressedForeground Color X Menu.acceleratorSelectionForeground Color X X X X Menu.arrowlcon Icon X X X X Menu. background Color X X X X

(continued)

813 Appendix A

TableA-1 (continued)

...... ' ...... ' ...... ' .. .. '...... ' ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS Menu. border Border X X X X Menu. borderPainted Boolean X X X X Menu.checklcon Icon X X X X Menu.consumesTabs Boolean X X X X Menu.disabledForeground Color X X Menu.font Font X X X X Menu.foreground Color X X X X Menu.margin Insets X X X X Menu.selectionBackground Color X X X X Menu.selectionForeground Color X X X X MenuBar.background Color X X X X MenuBar.border Border X X X X MenuBar.font Font X X X X MenuBar.foreground Color X X X X MenuBarUI String X X X X Menultem.acceleratorDelimiter String X X X X Menultem.acceleratorFont Font X X X X Menultem.acceleratorForeground Color X X X X Menultem.acceleratorSelectionForeground Color X X X X Menultem.arrowlcon Icon X X X X Menultem.background Color X X X X Menultem.border Border X X X X Menultem.borderPainted Boolean X X X X Menultem.checklcon Icon X X X X Menultem.disabledForeground Color X X Menultem.font Font X X X X Menultem.foreground Color X X X X Menultem.margin Insets X X X X Menultem.selectionBackground Color X X X X Menultem.selectionForeground Color X X X X MenultemUI String X X X X menuPressedltemB Color X menuPressedltemF Color X menuText Color X X X X MenuUI String X X X X OptionPane.background Color X X X X OptionPane.border Border X X X X OptionPane.buttonAreaBorder Border X X X X OptionPane.cancelButtonText String X X X X

(continued) 814 UI Manager Properties

TableA-1 (continued) ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS OptionPane.errorlcon Icon X X X X OptionPane.font Font X X X X OptionPane.foreground Color X X X X OptionPane.informationicon Icon X X X X OptionPane.messageAreaBorder Border X X X X OptionPane.messageForeground Color X X X X OptionPane.minimumSize Dimension X X X X OptionPane.noButtonText String X X X X OptionPane.okButtonText String X X X X OptionPane.questionicon Icon X X X X OptionPane.warningicon Icon X X X X OptionPane.yesButtonText String X X X X OptionPaneUI String X X X X Panel. background Color X X X X Panel.font Font X X X X Panel.foreground Color X X X X PanelUI String X X X X PasswordField.background Color X X X X PasswordField.border Border X X X X PasswordField.caretBlinkRate Integer X X X X PasswordField.caretForeground Color X X X X PasswordField.font Font X X X X PasswordField.foreground Color X X X X PasswordField.inactiveForeground Color X X X X PasswordField.keyBindings KeyBinding[ I X X X X PasswordField.margin Insets X X X X PasswordField.selectionBackground Color X X X X PasswordField.selectionForeground Color X X X X PasswordFieldUI String X X X X PopupMenu. background Color X X X X PopupMenu.border Border X X X X PopupMenu.font Font X X X X PopupMenu.foreground Color X X X X PopupMenuSeparatorUI String X X X X PopupMenuUI String X X X X ProgressBar.background Color X X X X ProgressBar.backgroundHighlight Color X ProgressBar.border Border X X X X ProgressBar.cellLength Integer X X X X

(continued)

815 Appendix A

TableA-1 (continued) ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS ProgressBar.cellSpacing Integer X X X X ProgressBar.font Font X X X X ProgressBar.foreground Color X X X X ProgressBar.foregroundHighlight Color X ProgressBar.selectionBackground Color X X X X ProgressBar.selectionForeground Color X X X X ProgressBarUI String X X X X RadioButton.background Color X X X X RadioButton.border Border X X X X RadioButton.darkShadow Color X RadioButton.disabledOff Icon X RadioButton.disabledOn Icon X RadioButton.disabledText Color X X RadioButton.focus Color X X X RadioButton.font Font X X X X RadioButton.foreground Color X X X X RadioButton.highlight Color X RadioButton.icon Icon X X X X RadioButton.margin Insets X X X X RadioButton.off Icon X RadioButton.on Icon X RadioButton.pressedOff Icon X RadioButton.pressedOn Icon X RadioButton.select Color X RadioButton.shadow Color X . texticonGap Integer X X X X RadioButton. textShiftOffset Integer X X X X RadioButtonMenultem.acceleratorFont Font X X X X RadioButtonMenultem.acceleratorForeground Color X X X X RadioButtonMenuitem. acceleratorSelectionForeground Color X X X X RadioButtonMenultem.arrowicon Icon X X X X RadioButtonMenultem.background Color X X X X RadioButtonMenultem.border Border X X X X RadioButtonMenultem.borderPainted Boolean X X X X RadioButtonMenultem.checklcon Icon X X X X RadioButtonMenuitem.disabledForeground Color X X RadioButtonMenultem.font Font X X X X RadioButtonMenultem.foreground Color X X X X

(continued)

816 UI Manager Properties

TableA-1 (continued) ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS RadioButtonMenultem.margin Insets X X X X RadioButtonMenultem.selectionBackground Color X X X X RadioButtonMenultem.selectionForeground Color X X X X RadioButtonMenultemUI String X X X X RadioButtonUI String X X X X · Color X X X X ScrollBar.arrowBackground Color X ScrollBar.arrowColor Color X ScrollBar.arrowHighlight Color X ScrollBar.arrowShadow Color X ScrollBar.background Color X X X X ScrollBar. border Border X X X ScrollBar.darkShadow Color X ScrollBar.foreground Color X X X X ScrollBar.highlight Color X ScrollBar.maximumThumbSize Dimension X X X X ScrollBar.rninimumThumbSize Dimension X X X X ScrollBar. pressedArrowBackground Color X ScrollBar. pressedArrowHighlight Color X ScrollBar.pressedArrowShadow Color X ScrollBar.pressedThumb Color X ScrollBar.pressedThumbDarkShadow Color X ScrollBar.pressedThumbHighlight Color X ScrollBar.pressedThumblightHighlight Color X ScrollBar.pressedThumbShadow Color X ScrollBar.shadow Color X ScrollBar. thumb Color X X X X ScrollBar.thumbDarkShadow Color X X X X ScrollBar.thumbHighlight Color X X X X ScrollBar.thumblightHighlight Color X ScrollBar. thumbLightShadow Color X X X X ScrollBar. thumbShadow Color X X ScrollBar. track Color X X X X ScrollBar. trackDarkShadow Color X ScrollBar. trackHighlight Color X X X X ScrollBar. trackLightHighlight Color X ScrollBar. trackShadow Color X ScrollBar. width Integer X X ScrollBarUI String X X X X

(continued)

817 Appendix A

TableA-1 (continued) ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS ScroliPane.background Color X X X X ScrollPane. border Border X X X ScrollPane.font Font X X X X ScrollPane.foreground Color X X X X ScrollPane. viewportBorder Border X ScrollPaneUI String X X X X Separator. background Color X X X X Separator.foreground Color X X X X Separator.highlight Color X X X X Separator.shadow Color X X X X SeparatorUI String X X X X . background Color X X X X Slider. border Border X Slider.darkShadow Color X X Slider.focus Color X X X X Slider.focuslnsets Insets X X X X Slider.foreground Color X X X X Slider. highlight Color X X X X Slider.horizontalThumbicon Icon X X Slider.rnajorTickLength Integer X X Slider.minorTickLength Integer X Slider.shadow Color X X X X Slider. thumb Color X X Slider. trackWidth Integer X X Slider.verticalThumblcon Icon X X SliderUI String X X X X SplitPane.activeThumb Color X SplitPane.background Color X X X X SplitPane. border Border X X X X SplitPane.dividerSize Integer X X X X SplitPane.highlight Color X X X SplitPane.shadow Color X X X X SplitPaneUI String X X X X StandardDialogUI String X X X X TabbedPane.background Color X X X X TabbedPane.contentBorderlnsets Insets X X X X TabbedPane.darkShadow Color X X X X TabbedPane.focus Color X X X X TabbedPane.font Font X X X X

(continued)

818 UI Manager Properties

TableA-1 (continued)

...... ' ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS TabbedPane.foreground Color X X X X TabbedPane.highlight Color X X X X TabbedPane.lightHighlight Color X X X X TabbedPane.nonSelected Color X X TabbedPane.selected Color X TabbedPane.selectedTabPadlnsets Insets X X X X TabbedPane.selectHighlight Color X TabbedPane.shadow Color X X X X TabbedPane. tabAreaBackground Color X TabbedPane. tabAreainsets Insets X X X X TabbedPane. tabInsets Insets X X X X TabbedPane. tabRun Overlay Integer X X X X TabbedPane. textlconGap Integer X X X X TabbedPane.unselectedTabBackground Color X TabbedPane. unselectedTabForeground Color X TabbedPane.unselectedTabHighlight Color X TabbedPane. unselectedTabShadow Color X TabbedPaneUI String X X X X Table. background Color X X X X Table.focusCellBackground Color X X X X Table.focusCellForeground Color X X X X Table.focusCellHighlightBorder Border X X X X Table .font Font X X X X Table.foreground Color X X X X Table. grid Color Color X X X X Table.scrollPaneBorder Border X X X Table.selectionBackground Color X X X X Table.selectionForeground Color X X X X TableHeader.background Color X X X X TableHeader.cellBorder Border X X X X TableHeader.font Font X X X X TableHeader.foreground Color X X X X TableHeaderUI String X X X X TableUI String X X X X text Color X X X X TextArea.background Color X X X X TextArea.border Border X X X X TextArea.caretBlinkRate Integer X X X X TextArea.caretForeground Color X X X X

(continued)

819 Appendix A

TableA-1 (continued)

························································ ··································· ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS TextArea.font Font X X X X TextArea.foreground Color X X X X TextArea.inactiveForeground Color X X X X TextArea.keyBindings KeyBinding[ ] X X X X TextArea.margin Insets X X X X TextArea.selectionBackground Color X X X X TextArea.selectionForeground Color X X X X TextAreaUI String X X X X TextField.background Color X X X X TextField.border Border X X X X TextField.caretB~ate Integer X X X X TextField.caretForeground Color X X X X TextField.font Font X X X X TextField.foreground Color X X X X TextField.inactiveForeground Color X X X X TextField.keyBindings KeyBinding[ ] X X X X TextField.margin Insets X X X X TextField.selectionBackground Color X X X X TextField.selectionForeground Color X X X X TextFieldUI String X X X X textHighlight Color X X X X textHighlightText Color X X X X textlnactiveText Color X X X X TextPane.background Color X X X X TextPane.border Border X X X X TextPane.caretB~te Integer X X X X TextPane.caretForeground Color X X X X TextPane.font Font X X X X TextPane.foreground Color X X X X TextPane.inactiveForeground Color X X X X TextPane.keyBindings KeyBinding[ l X X X X TextPane.margin Insets X X X X TextPane.selectionBackground Color X X X X TextPane.selectionForeground Color X X X X TextPaneUI String X X X X textText Color X X X X TitledBorder. border Border X X X X TitledBorder.font Font X X X X TitledBorder. titleColor Color X X X X

(continued)

820 UI Manager Properties

Table A-1 (continued)

...... ' ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS ToggleButton.background Color X X X X ToggleButton.border Border X X X X ToggleButton.disabledBackground Color X X ToggleButton.disabledSelectedBackground Color X X ToggleButton.disabledSelectedText Color X X ToggleButton.disabledText Color X X ToggleButton.focus Color X X X ToggleButton.font Font X X X X ToggleButton.foreground Color X X X X ToggleButton.margin Insets X X X X ToggleButton.select Color X X X ToggleButton. text Color X X ToggleButton.textlconGap Integer X X X X ToggleButton. textShiftOffset Integer X X X X ToggleButtonUI String X X X X .background Color X X X X ToolBar.border Border X X X X ToolBar.dockingBackground Color X X X X ToolBar.dockingForeground Color X X X X ToolBar.floatingBackground Color X X X X ToolBar.floatingForeground Color X X X X ToolBar.font Font X X X X ToolBar.foreground Color X X X X ToolBar.separatorSize Dimension X X X X ToolBarSeparatorUI String X X X X ToolBarUI String X X X X .background Color X X X X Tool Tip. border Border X X X X ToolTip.font Font X X X X ToolTip.foreground Color X X X X ToolTipUI String X X X X Thee. background Color X X X X li"ee.changeSelectionWithFocus Boolean X X X X nee.closedlcon Icon X X X X Tree.collapsedlcon Icon X X X X Tree.darkCollapsedlcon Icon X li"ee.darkExpandedlcon Icon X Tree.drawsFocusBorderAroundlcon Boolean X X X X li"ee.editorBorder Border X X X X Tree.editorBorderSelectionColor Color X

821 Appendix A

TableA-1 (continued) ...... PROPERTY STRING OBJECT TYPE MOTIF MACINTOSH METAL WINDOWS Tree.expandedlcon Icon X X X X Tree.font Font X X X X Tree.foreground Color X X X X Tree.hash Color X X X X Tree.iconBackground Color X Tree.iconForeground Color X Tree.iconHighlight Color X Tree.iconShadow Color X Tree.leaflcon Icon X X X X Tree.leftChildlndent Integer X X X X Tree .line Color X Tree.openlcon Icon X X X X Tree.rightChildindent Integer X X X X Tree.rowHeight Integer X X X X Tree.scrollsOnExpand Boolean X X X X Tree.selectionBackground Color X X X X Tree.selectionBorderColor Color X X X X Tree.selectionForeground Color X X X X Tree.textBackground Color X X X X 'Itee.textForeground Color X X X X TreeUI String X X X X Viewport. background Color X X X X Viewport.font Font X X X X Viewport.foreground Color X X X X ViewportUI String X X X X Color X X X X windowBorder Color X X X X windowText Color X X X X ...... TableA-1: UIResource Elements for the predefined look and feels

822 APPENDIX B About the CD-ROM

THE COMPANION CD-ROM FOR John Zukowski's Definitive Guide to Swing for Java 2 is a hybrid that is readable on Wmdows 95, 98, and NT 3.5 or later, and UNIX operating systems. This appendix tells you what you'll find on the CD and a little bit about how to use it.

Loading the CD Contents

After you insert the CD-ROM into the appropriate drive, nothing will happen. You must manually copy the contents from the CD-ROM to your local hard drive. The copying can be done with Explorer, File Manager, or from the command line. With Explorer /File Manager, just drag the contents of the Zukowski_ code directory from the CD-ROM to wherever you wish to install it. The command examples that appear later in this appendix were written under the assumption that you've copied the CD contents to the root level on your local PC hard drive or under your home directory on UNIX. From the command line on a PC, enter a command similar to the following, depending upon which is your CD-ROM drive and where you wish to install the contents: xcopy /s d:\Zukowski_code c:\Zukowski_code

Be sure to answer "D" for directory when xcopy asks if the destination is a file or directory. To use the contents of the CD, you must have a system that is capable of running the Java 2 platform, sometimes referred to as JDK 1.2. For about 95 per• cent of the examples, you can get by with a JDK 1.1 runtime environment. However, with the JDK 1.1 environment, you will come across some examples that will not work without modification. The actual recommended system requirements are dependent on the Java platform you are using. Review the requirements that came with the Java Development Kit you are using.

823 AppendixB

What's on the CD?

The CD-ROM contains all the source code and compiled class files from the pro• gramming examples in the book, along with some pictures of my dog and various other image files used in the examples. The files are grouped by chapter number and will be found in subdirectories of the individual chapter directories. You can copy the whole directory tree to your hard disk or load an individual source code file into your favorite editor or Java IDE from the CD and start work• ing with it. As described in the following section, you will need to have a directory containing certain utility classes in your CLASSPATH or store· a Jar file in the jre\lib\ext directory. All of the source examples use the default package. If you decide to reuse anything, feel free to recompile the classes into a package structure appropriate to your development environment. In order to give you maximum flexibility, I didn't want to force a package structure into the examples based on the chapter in which a class was defined.

Some Tips on Using the CD

What I'm about to say is very important and addresses the single biggest thing that Java product users complain about: In order to use the examples found in this book, you must add the zukowski-swing. jar file found on the CD-ROM to your CLASSPATH. This is because you need to tell Java about certain utilities classes that many of the example programs use. Assuming you've copied the Zukowski_code directory tree from the CD-ROM to the root-level of your local hard drive, the appropriate CLASSPATH settings are noted in the following two sec• tions of this appendix.

NOTE UNIX users should use similar CLASS PATH settings that include the appropriate directory names for their UNIX platform. Remember: In UNIX, a: (a colon) rather than a; (a semicolon) is used as the separator character for the CLASS PATH on Windows platforms.

For the Java 2 Platform

You'll need to use a command similar to the following under Windows, with the exact setting dependent on where you place the copy of the JAR file: set CLASSPATH=c:\Zukowski_code\zukowski-swing.jar;.

824 About the CD-ROM

TIP For the Java 2 platform, you can take advantage of the Java Extensions Framework and just copy the zukowski -swing. jar file to the jre\lib\ext directory under your JDKinstallation directory. If you do this, you will not need to alter your CLASSPATH.

You'll need to use a command similar to the following under UNIX, with the exact setting dependent on where you place a copy of the JAR file and what login shell you use: setenv CLASSPATH /home/username/Zukowski_code/zukowski-swing.jar:. or possibly

CLASSPATH = /home/username/Zukowski_code/zukowski-swing.jar:. export CLASSPATH

For the Java 1.1 Platform

Although this book covers Swing for the Java 2 platform, most of the examples in this book should work with the latest version of Swing for JDK 1.1. Using the code for JDK 1.1 with Swing installed requires a slightly longer CLASSPATH setting, and you may need to change the directory to the one specific to the "point" release of the JDK you are using and/ or the JFC Swing release. Here's an example of what you can use: set CLASSPATH=c:\jdk1.2.2\lib\classes.zip;c:\swing- 1.1.1\swingall.jar;c:\Zukowski_code\zukowski-swing.jar;.

If you would like to preserve the old CLASS PATH settings and just append the zukowski- swing. jar file, you can enter the following, assuming you've placed the JAR file in the designated directory tree: set CLASSPATH=%CLASSPATH%;c:\Zukowski_code\zukowski-swing.jar

Places to Go for More Information

Although the CD-ROM doesn't include a Java Development Kit or a JFC 1.1 with a Swing 1.1 release, you can get the latest releases from the Web fairly easily.

825 AppendixB

(Because point releases, including betas, do seem to be appearing frequently, this option seemed like the best choice for a book on Swing.) For a list of Java Development Kits for different platforms, see the list I main• tain at http:/ /java.about.com/msub2.htm. A fast kit for Windows platforms is available from IBM; it's called the IBM Developer Kit and Runtime Environment for Windows, Java Technology Edition. For the latest JFC with Swing release, visit http:/ /java.sun.com/products/jfc, although an early access version may be avail• able at the Java Developer Connection at http:/ /developer.java.sun.com/ developerI earlyAccess/ jfc/.

NOTE: To the best of my knowledge, the examples in this book do not contain any code that is affected by the Y2K boundary. However, I cannot guarantee that user code written using these examples will be free ofdefects that may cause Y2K problems. The java runtime itself is Y2K compliant as of]DK 1.1. 6. For more information on the Y2K compliance ofSun's Java technology products, see http://www.sun.com/y2000/cpl. html.

If You Have Any CD Problems

For technical support on using the CD, please send an e-mail message to [email protected]. Your e-mail should include the nature of your problem or question, what system you are running Swing on, what JDK and Swing ver• sions you are using, and the setting for your CLASSPATH. Finally, please be sure to tell us the best way to contact you.

826 Index

A AbstractTableModel, 707-724 about, 690 subclassing, 707, 708 abstract classes, 767 using in place ofDefaultTableModel, 712 notation for, 4 AbstractUndoableEdit . See AWT about, 783 AbstractAction commands, 793 about,40,41,42-44 methods, 801 implementation, 188-189 subclasses, 780, 789, 801 method, 189,251 accelerators properties, 44-45 about, 53, ll4 public subclasses, 45 examples, 166,419-422 See also TextAction }Menu objects with, 189 AbstractBorder JMenultem objects with, 196 about, 235 accept() constructor, 235 FileFilter, 356 example, 230 javax.swing.filechooser, 359 methods, 235-236 accessory panels, adding, 359 subclassing, 251 Action AbstractButton about,40-41,42, 196 about, 75, llO constants, 45 ButtonGroup, 127 for locating, 596, 597-598 children, ll3 disabling, 189 class hierarchy, 111 finding an, 599 current state of, 113 methods, 42, 597 event handling, ll6-ll7 modifying properties of, 43 example, ll6-ll7 objects, 188-189 finding the selected, 130 predefined implementations, 537 internal positioning, ll5-ll6 See also TextAction mnemonics, I 15 Action objects, 589, 596, 786 position constants, ll6 ActionButton, 47, 48-50, 539 properties, ll1-113, ll5, 209 ActionButtonSample, 120-121 JToggleButton use of, 134 ActionEvent, 34, 120, 506 subclass default alignment, 371 ActionListener UML relationship diagram, 112 Action interface and, 40 AbstractColorChooserPanel, 326, 336, 338-340 actionPerformed() as an, 189 AbstractDocument defining apart from a component, 188 about,73,522,542 examples,23-24,46,54 inner class, 784 interface extension, 188 properties, 542-544 with }Button events, 46, 120-122 support for listeners, 796 with }CheckBox events, 143 See also PlainDocument with JCheckBoxMenultem events, 206 AbstractDocument.AttributeContext, 602 with JColorChooser buttons, 331 AbstractDocument.Content, 604 with JComboBox events, 502, 505-506 AbstractDocument.DefaultDocumentEvent, 790 with JFileChooser, 352, 354 AbstractLayoutCache, 681 with JMenultem events, 182-183 AbstractListModel with JRadioButton events, 153-156 data model, 459 with JRadioButtonMenultem events, 211 methods, 461,470 withJScrollPane,415-416 subclassing, 4 71-4 72 with JTextField events, 559 See also DefaultComboBoxModel with JToggleButton selection events, 134 with KeyStroke, 51 objects, 797

827 Index

ActionListener (continued) alignments of components, 371-376 with Swing text components, 558 JLabel, 101, 102, 372 timer notification of, 66 ]Table columns, 711 using to perform cut operation, 537 Text field, 532 Action.NAME, 46 ALL_COLUMNS, 715 actionPerformedO Alt-keystroke mnemonics, 53, 114, 180 Action, 42 Ancestorlistener with ]Component events, 91-92 JColorChooser, 333 AnUndoableComponent, 797-798 JMenu, 189 Applet, 273 Action.SHORT_DESCRIPTION, 46 applets Action.SMALL_ICON, 46 download times, 7 ActionsMenuBar, 595-596 with menu bars, 172 ActionTester, 43-44 using Swing components, 273 ActivatedHyperlinkListener, 580-581 applications Activator (Java plug-in code), 7 cascading menus for, 166-170 Activel..abel, 763 MDI (multi-document interface), 13, 255, ActiveSample, 764 276 ActiveValue, 760, 762 APPROVE_SELECTION (JFileChooser), 352, 354 example, 763 Arraylist example, 461 add() ArraylistComboBoxModel, 4 72-4 73 ButtonGroup, 130 arrays Component, 371, 376 of arrays, 692 Container, 172, 173, 187, 195-196,221,403 Object, 684 DefaultMutableTreeNode, 665 using AbstractTableModel, 708 JMenu, 187 arrow keys, 419 JPanel, 124, 338 attributes JSplitPane, 398 Element, 541 addActionlistener() (JButton), 24 See also client properties addAuxiliaryLookAndFeel() (UIManager), 781 AttributeSet addCellEditorlistener() (CellEditor), 654 about, 589, 601 addChoosableFileFilter() (JFileChooser), 357, 358 definition, 605 addChooserPanel() (JColorChooser), 336, 340, interfaces, 615 345 andJTextPane,582 addCustomEntriesToTableO key constants, 607 (DefaultMetalTheme), 779 objects, 611 addEdit() ParagraphConstants.TabSet, 612 CompoundEdit, 793 Auto resize mode constants, 700 UndoManager, 795 AWf addElement() approach, 10 DefaultlistModel, 462 focus manager, 62 MutableComboBoxModel, 4 71 focusing capabilities, 40 addlistSelectionlistenerO (JUst), 487 layout managers, 369, 371 addNotify() (JComponent), 91 MouseEvent/Mouselistener, 489 addSelectedlnterval() (Jlist), 490 painting model, 80 addSeparatorO porting programs to Swing, 8, 15, 549 JMenu, 187, 192 release 1.1 WopupMenu, 196,201 event listener lists, 33 JToolBar, 226 event listeners, 34 JToolbar, 221 way of listening, 430 addSourceElements() (DuallistBox), 492 AWf components addTab() (JTabbedPane), 403 adding to JPopupMenu, 195 addUndoablelistener() (UndoableEditSupport), as DefaultCellEditor, 646 797 limitations of, 7 addXXXListenerO, 22 mixing with Swing components, 195 Adjustmentlistener parts used by Swing, 1 with JScrollBar events, 430-431 setting the focus, 53-54 with I Slider, 438 Swing replacements for, 8-10, 375 alignment values, 371, 378-381 text components, 521

828 Index

AWT containers, 255 bound properties (continued) AWTWindow objects, 10 AWTEventMulticaster, 33 JinternalFrame, 278, 279 axis point, 376 BoundedChangeUstener, 431-432,438-439 axis settings, 371 vrithJProgressBar,454-455 BoundedRangeModel argurnentforJScrollBar,430 asking for extent of, 531 B creating JProgressBar from, 448 definition, 425-426 and }Slider orientation, 437 BackgroundSample, 526 and ITextField, 457-458 BasicColorChooserUI, 335 method, 433,439 BasicComboBoxUI, 516 properties, 426,427,428,431,437 BasicDirectoryModel, 460 BoundSample, 32 BasicLookAndFeel, 746 Box subclassing, 776 about, 383-384 BasicMenuUI, 220 areas in that grow, 387-388 BasicSplitPaneDivider, 396 and BoxLayout, 371 BasicSplitPaneUI, 396 constructor, 384, 385 BasicTextAreaUI, 73 creating rigid areas, 388-390 BasicTextUI, 73 glue in a, 377-388, 389 Bevel color analysis, 241 and JRadioButton, 150 BevelBorder methods,384-385,387-388,389 about, 239-240 orientation, 384-385 constructors, 240 properties, 386 factory methods, 240-241 relationship diagram, 384 sample of raised/lowered, 240 Box.Filler, 383, 387 Book, 635 BoxLayout objects, 637 about, 370 BookCellRenderer, 636--637 andBox,383 BookTree, 638 changing, 386 Border constants, 384 class diagram, 230 constructor, 370-371 defined,229 examples,370,372,374,375,376 exarnples,230,251 andJPopup~enu, 188 insets areas, 231 managers, 381 and JavaBeans, 235 BoxSample, 386 location of, 230 breadthFirstEnumerationO methods, 231 (DefaultMutableTreeNode), 669 predefined classes of, 236-251 browsers BorderFactory, 230, 233-234 using Svring components vrithin, 7, 16-17 factory methods, 246-248 using to test Swing applets, 273 BorderLayout,222,256,273,284,369 bugs borders, 229-253 BasicColorChooserUI, 335 creating your own, 232, 251-253 Java2, 614 vrith different thicknesses, 243 JComboBox, 519 drawing, 81 Metalworks system demo, 781 factory methods for, 237 Sun Solaris, 297 and Niewport, 418 Svring release 1.1, 58, 187 vrith red Jines, 234 TreeUI cache, 634 soft beveled, 234 version differences and, 2 of Svring components, 229 See also errors three-dimensional, 239-240 buildChooserO (AbstractColorChooserPanel), 338 titled, 246 Button, 117, 120 bound properties button labels, 464 about, 31 localized, 314 event listener for, 91 }Component, 91

829 Index

ButtonGroup Caret about, llO, 128-130 about, 550-552 for check boxes, 139 example, 553 defined, 127 properties,552-553 example, 128 Swing text component use of, 522 JRadioButton use of, 148, 150-152 UML relationship diagram, 550 methods, 130-131 CaretEvent,554-556 toggleable components in, 127 CaretListener, 554-556 ToggleButton Model and, 129-130 CaretSample, 555-556 ButtonModel, llO, ll3-ll4, 127, 144 cascading menus for applications, 166-170 buttons CD-ROM, using book's companion, 823-826 approval, 352, 354 CellEditor arrow, 428 about, 642-643 Automatic Increase, 319 methods,649,653-657, 739 Box container, 385 CellEditorListener, 649, 654 Cancel, 301,315,317,319,323,329-330, objects, 642, 655, 739 331-333,351,352 cells changing background colors of, 753, 755, JList, 479 759 JTable, 690 changing colors of, example, 31-32 ChangeEvent for closing a , 26 with CellEditorListener, 649 configuring in button area, 293 and ChangeListener combo, 33 customizing appearance of, Ill and JMenu, 190-191 cut, copy, and paste, 537 ChangeListener Default, 557 with BoundedRangeModel, 426 deselecting selected, 129, 131 with Caret, 554 having none on option pane, 295 DefaultBoundedRangeModel and, 426 in JSplitPane, 391, 393 with I CheckBox events, 144-145 on a JToo!Bar, 590 with JColorChooser, 329 keeping depressed when selected, 10 with JMenu events, 191 keystrokes registration example, 51-53 with JMenuitem events, 181-182 layered, 377, 378 with JProgressBar, 454-455 Manual Increase, 319 with JRadioButton events, 157-162 No, 301 with JScrollBar events, 431-433 OK, 301,329-330,331-333 with JSlider, 438 Open, 351,352 with JSlider slider, 308-3ll radio, 94 withJTabbedPane,405 Redo,784,786 with JToggleButton selection events, Reset, 329-330 135-137 selection examples, 27-29, 378-381 list notification, 178 setting default, ll9 with Style, 602, 615 Start, 319 ChangeLook, 749, 750-751 toggle, 127-163 ChangeUpdate() (DocumentListener), 548 Undo, 784, 786 check box editor for JTree, 642 Yes,30l Checkbox/CheckboxGroup, 152 ButtonSample, 28-29 CheckBoxNode creating, 650-651 CheckBoxNodeEditor, 653-660 CheckBoxNodeRenderer c creating, 651-653 CheckBoxNodeTreeSample, 660-661 cancelCellEditingO (CellEditor), 655 CheckBoxUI, 139 Canvas, 122 children() (TreeNode), 668 cardinal relationships, 5 ChooserTableSample, 742-743 CardLayout, 369, 400 See also JTabbedPane

830 Index classes column headers aggregation relationships, notation for, 5 icons in, 730-732 associating event listener with, 24-25 JScrollPane, 417 Beanlnfo for, 80 JTable, 690, 707 dependency relationships, notation for, 4-5 removing, 695-696 interface relationships, notation for, 4 spanning multiple columns, 734 java.swing.filechooser.FileFilter, 349, 359 COLUMN_HEADER, 410, 414 java.util.Hashtable, 45 ColumnModelSample, 727-728 javax.swing.undo, 15 columns list of Swing implementations, 767-768 aligning, 711 look and feel JTable fixed, 709-711 multi-selection of files by, 354 manipulating, 725-726 names of AWf and Swing, 8-9 resizing, 699-702 notations for in UML diagrams, 4-5 ComboBoxEditor, 510-512 special, 315 example of custom, 513 Swing with JComboBox, 498 naming of, 8-9 ComboBoxModel, 75, 459, 469 usingwithJDK 1.1, 16-17 implementations, 471 Swing abstract root class, 70 See also MutableComboBoxModel Swing border, 230 ComboTableCellRenderer, 737 See also abstract classes Command, 789, 790 See also properties Command Design Pattern, 789 See also Swing components ComplexCellRenderer, 482, 501 CIASSPATH, setting for IE, 273 ComplexRenderingSample, 483-484, 501 clearSelection() (}List), 490 Component (AWf) Client, 790 about, 80 clientproperties,84-85, 764-767 events, 92-93 clipboard access, 536-539 and JLayeredPane, 255-256 clone() (Object), 681 labeling positions within JSlider with, 442 closed intervals, 461 objects, 408, 510 Color properties, 55, 57,58 column of, 736, 737 using Container add() with, 403 ComboBoxEditor for, 510-511 Component (Decorator design pattern), 715 with JColorChooser, 339, 340 component mnemonic. See mnemonic objects, 326, 511, 512, 759 component.getName(), 403 in UIDefaults table, 760 Componentlistener, 265 ColorChooserComponentFactory, 326, 334, components 336,347 aligning, 371, 372, 373, 374, 375, 376 ColorChooserEditor, 739-742 vertically,373-374,376 ColorChooserUI, 326, 338 comer, 415 ColorComboBox, 513-514 creating row or column of, 390 colors creating single row or column of, 383 background, 31, 145,331 data models for, 75-77 button background, 753, 755, 759 delegates, 767-768 choosing, 13, 325-348 determining positions of contained, 381 with TableCellEditor, 736 with differing alignments, 374-375, 377 custom tooltip text, 95 direction-independent glue, 387,389 customizing, 777 glue,387-388,389 text component, 551 grouping in JDialog, 326 ColorSample, 325, 327-328, 329 in a JLayeredPane, 260-261 ColorSamplePopup, 330-331 within JSplitPane, 393-396 ColorSelectionModel, 326, 328-329 larger, 375-376 ColorTableModel, 738-739 displaying, 407, 417 data model, 742 layering of, 376 ColorUIResource, 759 laying out, 371-376 locating pop-up window over, 295 logical vs. visual parts of, 75 mixing Swing and AWf, 63 opaque, 404

831 Index

components (continued) content creating bold and italic, 608, 611 opaque renderer, 481 multi-attributed, 10 opaque text, 526 redisplaying, 258 positioning within a container, 370 See also text rigid, 389 content pane, 256, 257 with the same alignments, 372-374 See also Container scrolling support for, 411 CONTIGUOUS_TREE_SELECTION, 679 sharing a data model across, 517-519 controller, UI delegate as, 745 sharing a model across, 427 convertValueToText() (JTree), 640 subclasses, notation for, 4 coordinates, specifying, 232 superclasses, notation for, 4 copy() transparent, 404 JPasswordField, 539 z-order within JLayeredPane, 259 JTextComponent, 527,537 Composite design pattern, 245 copylnto() (DefaultListModel), 469 CompoundBorder, 245-246 *_CORNER, 410,414 CompoundEdit corners in JScrollPane, 415--416 about, 783, 784, 793 createArrowButton() (}Button), 516 state chart, 794 CreateColorSamplePopup, 331-333, 345-346 subclass, 784, 794 createDefaultColumnsFromModel() (JTable), 724 ConcreteCommand, 789, 790, 801 createDefaultDivider() (BasicSplitPaneUI), 396 ConcreteComponent, 715 createDialog() ConcreteDecorator, 716 arguments, JOptionPane, 300, 316 configureEnclosingScrollPane() (}Table), 696 for Java 2 and JDK 1.1, 297 confirm pop-ups, 302 JColorChooser, 331-333 constrained properties, event listener for, 91 createDisabledlmage() (GrayFilter), 110 consume() (KeyEvent), 60, 544 createEmptyBorder() (EmptyBorder), 237 Container createFloatingFrame() (}Frame), 769 defined, 26 createGlue() (Box), 389 events, 92-93 createHorizonalBox() (Box), 384-385 and I Component, 80 createlnternalFrame() (JOptionPane), 300 and JLayeredPane, 255-256 createRadioButtonGrouping() methods, 386 ActionListener, 153, 155 container objects, 122 RadioButtonUtils, 150 See also high-level container objects createRigidArea() (Box), 389 Container.add(), 388 createScrollPaneforTable() (JTable), 694 Containerlistener with JFrame events, 265 createStandardLabels() (Hashtable), 444 containers createToo!Tip() (ToolTipManager), 94 Action and, 42 createValue() (LazyValue), 670 BoxLayoutand,387 createVerticalBox() (Box), 384--385 determining positions of components in, Ctrllkeystroke accelerator, 180 381 CTRL-, 574 focus cycle restricted, 58, 59 position and movements, 550-556 horizontal and vertical, 385-386 CustomBorderSample, 481--482 moving among components within, 54 CustomPanelPopup, 345-346 positioning components within, 370 CustomToo!BarUI, 769, 776 Swing component, 14 CustomToo!BarUI.FRME_IMAGE_ICON, 769, 780 identifying, 80 cut() See also Box JPasswordField, 539 See also BoxLayout JTextComponent, 527, 537 See also JScrollPane cutAction, 537 See also JSplitPane CutPasteSample, 538-539 See also JTabbedPane See also Niewport contains() Component, 95 DefaultListModel, 469

832 Index

D DefaultMutableTreeNode about,619,662,664 building hierarchies, 665-666 data models constructors, 664 for bounded range components, 425 creating, 664 listing of changes to, 464 example, 666 predefined, 75-77 methods for traversing trees, 668-670 shared, 73-75,517-519 properties, 639, 666-667 for text components, 522 relationship methods, 667-668 See also selection models subclass, 670 data selection controls, 459-519 DefaultSample, 557-558 DataFlavor, 672 DefaultSingleSelectionModel, 178, 400 DataFlavor.javaFilelistFlavor, 674 DefaultStyledDocument Date, 711 about,522,576,601 debugGraphics settings, 88 creating, 604 decode() (Color), 511 populating, 606-607 Decorator, 716 properties, 604 Decorator design pattern, 715-716 DefaultTableCellRenderer, 702-705 DefaultBoundedRangeModel, 425, 427 DefaultTableColumnModel, 690,725-726 DefaultButton, 119-120 DefaultTableModel DefaultButtonModel, llO, ll4, 127, 185 about, 690, 712 properties, ll4 constructors, 712-713 DefaultCaret, 550, 551 creating, 712-713 DefaultCellEditor methods, 713-714 about,390,619,642,643 properties, 714 constructors, 644 DefaultTreeCellEditor creating, 644-646 about,619,642,646-647 properties, 646 constructors, 64 7 and TableCellEditor, 735-736 when not to use, 653 when not to use, 653 DefaultTreeCellRenderer DefaultCellRenderer, 690 about, 619,633 DefaultColorSelectionModel, 326 for nonleafnodes, 651 DefaultComboBoxModel properties,633-635 about,459-460,470 DefaultTreeModel, 662, 678-679 constructors, 470-471 DefaultTreeSelectionModel, 620, 681-682 creating from array vs. Vector, 4 70 delegate object, 72 properties, 471 delegation-based event handling, 15, 21-39 DefaultDesktopManager, 275, 287 depthFirstEnumeration() DefaultDocumentEvent commands, 783 (DefaultMutableTreeNode), 669 DefaultEditorKit, 537, 596 Desktop, 275 DefaultEditorKit.copyAction, 598 Desktop Icon DefaultEditorKit.cutAction, 598 DesktopManager, 275, 287 DefaultEditorKit.pasteAction, 598 DesktopPane, 283 DefaultEditorKit.readOnlyAction, 598 destinationElements() (DualListBox), 493 DefaultEditorKit.writableAction, 598 diagrams, how to read, 4-5 DefaultFocusManager, 40, 62-64 dialog boxes DefaultHighlighter, 550, 551 confirm, 301, 302 DefaultHighlighter.HighlightPainter, 551 displaying in, 454 DefaultJOptionPane, 307 input, 302 DefaultlistCellRenderer, 479,480-483 internal frame for, 277 DefaultListModel recycling, 297 about, 459 tabbed, 400 methods,462,463,464,469 two unclosable on screen, 565 properties, 463 DiamondAbstractButtonStateicon, 209 DefaultListSelectionModel, 698-699 Diamondicon, 105-106,208,483,731,736 properties, 486-487 lazy version of, 760 DefaultMetalTheme, 779-781 Dictionary, 436 }Slider, 442, 443 die() (UndoManager), 791,792

833 Index

Dimension, 389, 395, 760 E direction-independent glue components, 387, 389 directories echoCharlsSet() (JPasswordField), 568 icons for nontraversable, 362 edit commands, tracking history of, 794 selecting, 348, 350, 359 example, 166 directory list filters, 355-359 EditableColorColumn, 737-738 disableSwingFocusManager() (FocusManager), EditComboBox, 508-514, 512 63 editingCanceled() (Cel!EditorListener), 649 discardAIIEdits() (UndoManager), 795 editingStopped() (Cel!EditorListener), 649 DISCONTIGUOUS_TREE_SELECTION, 679, 681 EditorContainer, 619 display EditorKit, 536, 576, 590, 616 of hierarchical data, 12, 619 EditorPaneSample, 581 JOptionPane, 295-198 Element oflarge components, 407, 417 and DocumentEvent, 549 of lists of properties, 755 makeup of a Document, 541-542 of multi -line messages, 305 objects, 544 of pop-up messages, 93 elements of stylized text, 589 in columns, 711 oftabbed cards, 14 lazy or active, 760 of two-dimensional row I column sorting }Table, 715-724 information, 11 elements() (DefaultListModel), 469 Document ElementSample,543-544 about, 72 EmptyBorder, 236-237 and Command Design Pattern, 789, 790 end() creating custom implementations of, CompoundEdit, 793 544-548,561 StateEdit, 803 data model, 784 UndoManager, 794, 795 definition, 540-541 ensurelndexlsVisible() (JList), 479 Element makeup of, 541-542 Enter key implementations, 522, 527 depressing in text component, 591 with a JPasswordField, 567 input focus for, 120 with JTextPane, 601 within JTextField, 527 with restricted input, 547 selection by pressing, 53 sharing between JTextArea components, 75 Enumeration undoable operations, 784 of all a node's children, 668-670 use of document property with, 532 obtaining an, 469, 493 See also AbstractDocument equals() for checking object equality, 238 DocumentEvent, 72, 523, 548-549 errors DocumentEvent.ElementChange, 549 AWfError, 371 DocumentEvent.Event'IYJle, 549 glue component, 388 DocumentListener, 540, 548-549, 561-562 insert() Action, 196 Document.StreamDescriptionProperty; 533 }Frame , 264 Done state, 791, 792 JMenu accelerator property, 189 double-buffered drawing, 82, 123 runtime, 412 double-click events, 489 JFrame,26,27,265 DoubleTitle, 250 StackOverflowError, 233 drag and drop events, 671-677 tear-off menu, 190 Draggableltee,671-672,674,677 See also bugs DragGestureListener, 671 See also exceptions dragGestureRecognized() (DragGestureListener), EscapeDialog, 271-272 671 EtchedBorder, 242-243 dragging events, 671-677 EvenOddRenderer, 703-704 DragSource, 671 Event, 180,280 drop() (DropTargetListener), 674 event delegation sequence diagram, 23 DroppableList, 677 event-dispatch thread, 64, 66, 67 DropTargetListener, 674 DuaiListBox example, 492-497 dump-model, 597 DynamicUti!TreeNode, 671 834 Index event handling F and component layering, 377-378 delegation-based, 15,21-39 multithreaded Swing, 64-68 F8key, 394 paint events, 64 Factory design pattern, 230 Swing, 14-15 factory methods for JOptionPane, 300-301 Swing component set, 21-69 File,355 Swing-specific capabilities for, 39-53 examples, 166, 187 event listeners file reading and writing, 536 adding and removing of, 34, 37 FileChooserUI, 361 AWT release 1.1, 34 FileDiruog,9,348,359 creating an instance of, 24 FileFilter, 349, 355-359 custom, 37 FilenameFilter, 355 defining, 23-24 filenames, selecting, 348 event registration methods for, 114 FileSamplePanel, 351-352,354 example of, with button selection, 28-29 FileSystemView, 349,350,361 inherited ]Component, 93 FileView, 349,362-364 management of lists, 33-39 UIResource elements, 367 methods used for, 22 filtering streams, 322 objects supported by ActiveButton children, filters, file and directory, 355-359 113 FindAction, 599 OK/Cancel, 331-333 findAction() (Action), 539 registering with components, 24-25 findColorLabel() (JColorChooser), 340 sharing across components, 25 findColorPosition() (JColorChooser), 340 for Swing text components, 548-558 fireContentsChanged() (AbstractlistModel), 461 threads and, 64 fireEditingCanceled() (CellEditor), 655 using as observers, 23-25 fireEditingStopped() (CellEditor), 655 event-related class hierarchy, Swing, 41 firelntervffiAdded() (AbstractListModel), 461 event thread, 452 firelntervruRemoved() (AbstractlistModel), 461 EventlistenerList, 33, 37-39 fireXXX:() (AbstractTableModel), 707 EventQueue, 66 FixedHeightLayoutCache, 681 events. See event handling FixedTable, 709-711 See drag and drop events FlowLayout, 123, 273, 369 exceptions See also BoxLayout Badl.ocationException, 527,553,607 focus, defined, 53 CannotRedoException, 701, 784 focus cycles, 54, 58-60 CannotUndoException, 701, 784 focus management, 53-59, 60-61 ClassCastException, 405,412 FocusCycleConstrainedJPanel, 58 ExpandVetoException,686 FocusedTitleListCellRenderer, 480, 481, 502 IllegalArgumentException, 190, 193, 222, FocusListener 393,394,402,409,418,429,437,664 about, 53 InterrupediOException, 323 with JFrame events, 265 InterruptedException, 65 with JTextField events, 560-561 InvocationTargetException,65 with Swing text components, 559 IOException, 527 FocusManage~40,60,62-64 JTextfield ]Table editor, 735, 736 fonts, Japanese, 689 NullPointerException, 53, 648 foreign language coding, 314 PropertyVetoException, 91, 278 Frame,26,262,269 framelnit() (Frame), 266 thrown using Icon, 770 undo/redo, 796 frames undoable state changes, 793 buttons on, 26 when changing LookAndFeel, 749 closing, 26-29 See also errors customizing appearance of, 266 draggable toolbar for, 769 EbdtableJFrame,27-29,264,266 EXIT_ ON_ CLOSE, 264 internru,276,283 ExpandVetoException,686 managing within a desktop, 275 See also MDI (multi-document interface)

835 Index

G getPresentationName() (AbstractUndoableEdit), 801 getPreviewPanel() (JComponent), 347 GapContent, 604 getPreviousNode() (DefaultMutableTreeNode), get() 668 DefaultListModel, 469 getProgress() (ProgressMonitor), 317 Hashtable, 803 getProperty() (AbstractDocument), 542 get() (UIManager), 753 getPropertyName() (PropertyChangeListener), getAcceptAIIFileFilter() (JFileChooser), 358 278 getActions() (JTextComponent). 590, 598 getRoot() (TreeMode]), 669 getAuxiliaryLookAndFeels() (UI Manager), 781 getSelectedElements() (RadioButtonUtils), getBorder() (I Component). 229 155-156 getBorderlnsets() getSelectedlndex() (JComboBox), 505, 508 AbstractBorder, 235, 236 getSelection() (OptionPaneUtils), 296--298 Border, 233 getSharedAncestor() (DefaultMutableTreeNode), getCellEditorValue() (CeiiEditor), 653-654, 739 668 getChange() (DocumentEvent), 549 getSmallDisplaylcon() (Icon), 338 getChildCount() (MutableTreeNode), 664 getSubElements() (MenuElement interface), 215 getClass() on element in column, 711 getTableCeiiRendererComponent() getC!ientProperty() (JComponent), 765 (TableCellRenderer), 702 getColurnnClass() (TableMode]), 704, 711 getText().length(), 542 getComponent() (MenuElement). 215 getTreeCellEditorComponent() (TreeCeiiEditor). getContentPane() (JFrame), 26 648,657 getContent1'ype() (EditorKit), 578 getTreeCellRendererComponent() getDefaultChooserPanels() (DefaultTreeCeiiRenderer). 636 (AbstractColorChooserPane]), 34 7 getUIClassiD() (JToo!Bar). 768 getDefaults() (UIManager), 84 getValue() getDisplayName() (AbstractColorChooserPane]), Action, 45 338 JOptionPane, 295, 296 getEdit() (UndoableEditEvent), 796 getValuelsAdjusting(), 426 getEditorComponent() (ComboBoxEditor). 510 g.fillRect(), 232 getElementAtO (DefaultUstModel), 469 gifimages, 104, 109 getElements() (ButtonGroup), 130 needed for LookAndFeel, 776 getFileSelectMode() (JFileChooser), 359 glass pane getFileSystemView() (FileSystemView), 361 JRootPane,256,257,258 getimage() (Imageloader), 108-109 of RootPaneContainer implementer, 258 getinputValue() (JOptionPane), 295 glue components, 387-388, 389 getlnsetsO (JComponent), 236 glyphs, 104 getinstalledLookAndFeels() (UIManager), grabFocus() (JComponent). 55 747-748, 749, 781 Graphics, 232 getinteriorRectangle() (AbstractBorder), 236 Graphics.copyArea(), 419 getltem() (ComboBoxEditor), 511 GrayFilter, 110 getKeymap() (JTextComponent), 590 grayscales, 110 getKeyStroke() (KeyStroke), 50-51, 180, 181 GridBagLayout, 369, 370, 414, 497 getKeyStrokeForEvent() (KeyStroke), 50, 51 GridLayout, 369 getKeyText() (KeyEvent), 34 See also BoxLayout getLargeDisplaylcon() (Icon), 338 GroupActionRadio, 157-159 getListCellRendererComponent() GroupRadio, 152 (listCellRenderer). 480, 482 getmaxcharactersPerUneCount() (JOptionPane), 305 getModel() (BoundedRangeMode]), 433,439 getNextNode() (DefaultMutableTreeNode), 668 getPaintTicks() (JS!ider), 443 getPath() JMenu, 220 TreeExpansionEvent, 685

836 Index

H Icon (continued) methods, 104,208,338 handleEvent(Event), 15 objects, 730 hash table, UIDefaults, 745, 754 positioning }Label, 101, 102 Hashtable properties, 104 creating a tree from, 622-623, 664 state-aware, 140, 141-142 for creating tree nodes, 670 tiled through border area, 243, 244 if-null check with, 803 in UIDefaults table, 760 for }Slider position labels, 442-443 using, 106 for managing attributes, 602 Icon arguments, 293 methods, 444 IconCheckBoxSample, 142-143 for storage of undoable object states, 802 ICONIFIED, 264 text attributes, 589 icons See also java.util.Dictionary accessory, 360-361 HEADER_ROW, 715 column header, 730-732 headers. See column headers defining apart from a component, 188 hidden files, enabling display of, 358 diamond, 106, 208, 483 HIDE_ON_CLOSE, 271 file, 362 hidePopup() (JComboBox), 501 image on toolbar, 769 high-level container objects, 9-10, 79-80, 255 JCheckBoxMenuitem, 203, 205, 207-209 highestLayer() (JLayeredPane), 259 for JRadioButtonMenultem, 209-211 Highlighter, 522, 550-551 on JSplitPane dividers, 395-396 Highlighter.Highlight objects, 550, 551 JTree,630,633,645,647 horizontal , 221 MacLookAndFeel, 774 HORIZONTAL_SCROLLBAR, 410,414 menu, 167 hot-keys, 53, 114 in table headers, 731 HSB panel, 327, 336 Image, 360 HTML image backgrounds, creating, 525-526 displaying within a label, 113 image files document example, 541 GIF animated, 104, 109 and JOptionPane message text, 306 needed for LookAndFeel, 774-775, 776 support for JEditorPane, 575 Image objects (AWT), 106-107 tooltip text, 94 ImageFilter (AWT class), 110 using in rendered output, 102 Imageleon HTMLDocument, 522 about, 104, 106 HTMLEditorKit, 580 with AbstractButton, 115 HyperlinkEvent, 579-581 constructors, 107 HyperlinkEvent.EventType, 579 height and width of, 108 HyperlinkListener, 579-581 and MatteBorder, 243 hyperlinkUpdate() (HyperlinkListener), 579 objects, 108 properties, 108-109 in UIDefaults table, 760 using, 108 I ImageLoader, 108-109 indexOf() (DefaultListModel), 469 indexToLocation() (JList), 490 Icon INFORMATION_MESSAGE pop-ups, 301 about, 104 inherited events, 92-93 AbstractButton, 115 init() (}Menu), 220 check box, 139 initclassDefaults() (BasicLookAndFeel), 776 creating, 104-106 initia!Value, 294-295 exception thrown using, 770 input focus grayed-out, 110, 115 editors and, 643 }CheckBox, 140, 141-142 }Button showing, 53 JOptionPane, 312, 777 TextAction and, 589 JRadioButton, 148 TextAction objects and, 598 JTabbedPane, 403 input pop-ups, 298

837 Index

InputEvent masks, 51 interface definitions (continued) InputMethodllstener, 34 with JFrame events, 265 Scrollable, 412 insert() SingleSelectionModel, 177-178 JPopupMenu, 196 StateEditable, 803 MutableTreeNode, 663, 664, 665 Style, 615 insertElement() StyledDocument, 602 (MutableComboBoxModel), 471 TableCellEditor, 735 insertNodelnto() (DefaultTreeModel), 678 TableCellRenderer, 702 insertSeparator() TableColumnModel, 724-725 TableModel, 707 JMenu, 192 JPopupMenu, 196 TreeCellEditor, 643 TreeCellRenderer, 632 insertStringO Document, 544-545 TreeExpansionlistener, 685 StyledDocument, 585, 607 TreeModel, 678 insertTab() (JTabbedPane), 403 TreeModellistener, 679 insertUpdateQ (Documenilistener), 548 TreeNode, 662--663 TreeSelectionListener, 682-684 insets AbstractBorder, 235 TreeSelectionModel, 680 Border, 231, 233 TreeWillExpandlistener, 686-687 insets() (}Component), 236 UIDefaults.ActiveValue, 762 Insets objects, 233, 251 UIDefaults.LazyValue, 760 install() (TableHeaderSorter), 717 UndoableEdit, 791 installChooser Panel() UndoableEditListener, 796 (AbstractColorChooserPanel), 338,339 interfaces Integer, 42,296 Actionlistener, 40, 188 IntegerRangeDocument, 545-547 BoundedRangeModel, 425-426 interface definitions ColorSelectionModel, 326 Action,4o-41 ComboBoxModel, 75, 459 AtributeSet, 605 implementation relationships, Border, 231 notation for, 4 ButtonModel, 113 java.io.FileFilter, 349, 359 Caret, 551-552 Keymap,40 Careilistener, 554 KeySelectionManager, 503-504 CellEditor, 643 LayoutManager2, 371, 376 CellEditorlistener, 649 MenuKeylistener, 183 ComboBoxEditor, 510 Mouseinputlistener, 25, 29 ComboBoxModel, 469 multi-document, 13,255 DesktopManager, 287 multiple, for a component, 75 Document, 540-541 MutableComboBoxModel, 75, 460 DocumentEvent,549 notations for in UML diagrams, 4-5 Documenilistener, 548-549 Swing component data model, 76 FocusManager default implementation, 63 SwingConstants, 102 Highlighter, 551 TextUI, 73 Hyperlinklistener, 579 UIResource, 83 Icon, 104 InternalFrameAdapter, 280 InternalFramelistener, 279 InternalFrameEvent, 280 Keymap,556-558 InternalFrameiconifylistener, 285 listCellRenderer, 48o-483 InternalFrameListener, 280 listDatalistener, 463 invalidate() (}Component), 66 listModel, 460 invokeAndWait() (SwingUtilities), 65, 66, 450, 452 listSelectionModel, 485-486 invokeLater() (SwingUtilities), 65, 66,333 MenuDragMouselistener, 184 Invoker, 790 Menulllement,215 isBorderOpaque() (AbstractBorder), 235, 246 MutableAttributeSet, 605 isCellEditable() (CellEditor), 648, 656, 707 MutableComboBoxModel, 470 isEventDispatchThread() (SwingUtilities), 64 MutableTreeNode, 663 islnProgress() (UndoManager), 794 PopupMenulistener, 199 isLeaf() (TreeNode), 648 RootPaneContainer, 258 isManagingFocus()

838 Index

JComponent, 60, 61 java.util.EventObject class, 22 JTextArea, 573 java.util.Hashtable, 45 isSelected() (SingleSelectionModel), 178 javax.swing package, 230, 521 isSupportedLookAndFeel() (MacLookAndFeel), hierarchy, 7, 8, 15 773 javax.swing.border package, 235 isTraversable() (FileView), 362 javax.swing.colorchooser package, 326 ItemListener javax.swing.event package, 25, 38, 521, 621, 783 with JCheckBox, 655 javax.swing.filechooser.FileFilter subclasses, 359 with JCheckBox events, 144 javax.swing.plafpackage, 8, 759 with JCheckBoxMenuitem events, 206-207 javax.swing.plaf.basic package, 510 with JComboBox, 502 javax.swing.plaf.metal.Meta!LookAndFeel, 754 with JComboBox events, 506-508 javax.swing.table package, 689 with JRadioButton events, 156 javax.swing.text package, 521 with JToggleButton selection events, 135 javax.swing. tree package, 621 methods, 135, 144 javax.swing.undo package, 783, 789 itemStateChanged() (ltemListener), 135, 144 javax.util package, 783 JButton about, 117 and AbstractButton icons, 115 J and ActionListener, 23-24 for changing a look and feel at runtime, 749 changing background colors of, 753, 755, Japanese fonts, 689 759 JApplet constructors, 118 about, 255, 273 creating an Action, 46-49 layout manager, 273 custom coloration for tooltip for, 95, 96 protected method, 27 4 event handling, 120-122 and RootPaneContainer, 258 examples, 118,310-311 testing, 273-274 in JToo!Bar, 42, 223 JAR (Java archive) files, 7, 108 look and feel, 122, 123 Java methods, 24, 516 development of, 7 objects, 294 list of bugs, 2 properties, 118-120 Plug-ins, 16-17 selectedlcon, 134 programs showing input focus, 53 porting from AWf to Swing, 8 U!Resource elements, 122 undo and redo capabilities, 15 JCheckBox Web sites about, 6 about, 139 Java 2 and AbstractButton icons, 115 and bound properties ofJComponent, 91 constructors, 140-141 bugs, 614 default data model for, 128 compatibility with JFC releases, 16 editor for JTable, 735 drag-and-drop capabilities, 677 editor for JTree, 644, 645-646, 650 loading look and feel classes, 773 foreground or background color changes, new event listener, 34 145 and paint() Graphics argument, 81 look and feel, 146, 14 7 Software Developers' Kit, 66 parent, 131 Swing demonstration program, 17-18 properties, 140-142 Swing versions used with, 2, 16 sample components, 139 Java Database Connectivity (JDBC) query, 708 selection event handling, 143-146 Java Development Kit. See JDK UIResource elements, 147 Java Foundation Classes. See JFC UML relationship diagram, 140 JavaBeans properties, 85-87 vs. JRadioButton, 148 JavaFileView, 363-364 JCheckbox java.io package, 716 icon, 140, 141-142 Java.io.Filefilter, 349 See also JToggleButton java.swing.filechooser package, 349 java.util.Dictionary, 639 java.util.EventListener interface, 22

839 Index

JCheckBoxMenultem JComboBox (continued) about, 203 constructors, 203-205 sample components, 498 creating, 203-205 sample controls, 459 default data model for, 128 selection event handling, 502-508 event handling, 205-207 UIResource elements, 515 icons,203,205,207-209 UML relationship diagram, 499 look and feel, 207-209 JComboBox.KeySelectionManager, 502 properties, 205 }Component UIResource elements, 207 about, 79-80 UML relationship diagram, 204 capabilities of subclasses, 80-85 JColorChooser constants for keystrokes, 50 about,289,325-326 descendent subclasses, 79 and ComboBoxEditor, 511 event handling, 89-93 constructors, 327 focus-oriented properties of, 55, 57, 61 creating, 326-327 focusCycleRoot, 57, 58 data model, 328 hierarchy diagram, 79 event listeners, 328-329,331-333 managingFocus,57,58,61 examples, 13,325,327-328,329 methods,91,99,347,395,631, 765 factory method, 329 nextFocusableComponent, 57, 61-62 look and feel, 347-348 properties,81,85-89 methods,331,336,340,345,347 property methods, 229 panels, 336-347 PropertyChangeListener constants, 90 default, 337 registerKeyboardAction(), 49 pop-up window, 326, 329-331 requestFocusEnabled, 57 with preview panel, 335 JComponentTableCellRenderer, 730-731 properties, 333-334,347 JDesktoplcon, 275, 283 tabs,336 JDesktopPane UIResource elements, 348 adding internal frames to, 284 UML relationship diagram, 327 constructor, 284 using, 327-328 examples, 13,285-286 vs. TableCellEditor, 739 and JintemalFrame, 255 without preview panel, 334 look and feel, 284-285 JComboBox optimized drawing, 81 about, 75,407-499 properties, 284 bug, 519 UIResource elements, 285 cell renderer, 498 }Dialog for changing a look and feel at runtime, 749 about, 255, 269 constructors, 499-500 constants, 271 creating, 338, 499-500 constructors, 269-270 data model, 498 creating, 269-270 default interface, 470 event handling, 271-272 default renderer, 100 interfaces, 269 editor, 498 with JOptionPane, 290, 295, 304 editor for }Table, 735, 736 methods, 298, 300 editor for }Tree, 644-645, 646-648 modality, 269 element editing, 508-514 placing JFileChooser panel within, 353 examples,472,509 properties, 270-271 and JColorChooser, 337 protected methods, 273 and }List, 517 and RootPaneContainer, 258 and JOptionPane, 300 UML relationship diagram, 269 and JTextField, 509 JDK, 16 keystroke manager, 498 release 1.1 look and feel, 514-515-517 code that sorts the Action list, 594 methods,501,502-505,505 limitations, 524, 677 mouse and cursor events within, SOB loading look and feel classes, 773 pop-up button example, 516 and undo, 783 properties, 500-501, SOB release 1.2 beta, 367 renderers, 501-502, 512 release 1.0 event model, 15

840 Index

JEditorPane JinternalFrame (continued) about,10,521,575-576 290, 295, 304 as an HTML viewer, 576 and JOptionPane, constructors, 576--577 look and feel, 281-283, 282 frames, 283 event handling, 576, 579 palette with other example, 11 properties,91,277-279 look and feel, 582 and RootPaneContainer, 258 making read-only, 581 UI delegate, 283 281 properties, 578 UIResource elements, }Label support for HTML, 575 text/htrnl content type, 522 about, 99-100 UIResource elements, 582 alignments, 102 UML relationship diagram, 577 border examples, 230 content, 101 use of JTextComponent methods, 532-539 See also JTextPane creating, 100 default alignment, 371 JFC for other components, getting the latest release, 16 display of mnemonic 103 release 1.1 exceptions generated by, 53 event handling, 103 and Java2 platform, 16 example, 335 497 Swing versions used with, 2 and JComboBox, position, 442 undo operations, 783 for labelling I Slider look and feel, 103-104 JFileChooser about,289,348-350 methods, 529 in JTextField, 529-530 accessory panels, 359, 360 mnemonics label, 637 adding ActionListener to, 352, 354 with a non-empty 319 constants, 353-354, 359 and ProgressMonitor, 103,525 constructors,350-351 properties,100-102, 99 example, 349 sample components, me filters associated with, 358 subclasses, 633 100-102 look and feel, 363, 365-367 text/image positioning, 102 methods,353,355,357,358 text positions, 104 within a pop-up window, 353-354 UIResource elements, values, 763 properties,354-365 using active in, 106 UIResource elements, 366 using an icon UML relationship diagram, 350 See also DefaultListCellRenderer using, 351-352 JLayeredPane }Frame about, 259 in layers, 259-260 about,26-27,255,262 adding components and positions, 260-261 adding components to, 264-265 component layers constants, 259-260 constants, 263 creating, 259 constructors, 262-263 and JRootPane, 255-256 default, 264 layout manager, 259 event handling, 265-266 methods,259-260,260 event listener example, 92 optimized drawing, 81 interfaces, 262 positions, 261 and }Component, 262 properties, 262 layout manager, 264 JList methods, 769 about,8,300,301,473-473 properties,263-264,266 constructors, 474-475 protected methods, 266 with custom focus border cell renderer, 480 and RootPaneContainer, 258 data model, 459, 473 UML relationship diagram, 263 empty, 477, 479 JintemalFrame default renderer, 100 about, 13,255,276 in, 463 constants, 278 displaying ResultSet example, 674 constructors,276-277 droppable object 492-497 eventhandling,278-280 DualListBox example, 487-490 and JDesktopPane, 285-286, 287 event listening,

841 Index

]List (continued) JMenultem (continued)

andJComboBox, 497,498,517,519 subclasses, 182 andJScrollPane,476-479 UIResource elements, 185 look and feel, 491-492 UML relationship diagram, 179 methods,487,489,490 JOptionPane in and out of a JScrollPane, 4 77 about, 289-290 properties,475-479,480,486,489 button area, 290 renderers, 479-484 adding components to, 310-311 sample controls, 459 with complex message property, 308 scrolling support, 411 constructors,291-292,293,299 selecting elements within, 484-485 creating selection event handling, 490 automatically in pop-up window, 298 selection listener, 488 manually, 290-295 selection modes, 486 default UI delegate, 310 in single-selection mode, 489 and DefaultButton, 119 sizing entries within a, 477, 478 displaying, 295-198 UIResource elements, 492 examples, 13,296,301,301-304,302,303, UML relationship diagram, 474 304 JMenu. See also JMenultem factory methods, 299, 300-301 about,165, 170,185 in French, 315 Action objects and, 42 icons, 312,777 Action support, 46 area of, 290 adding items to, 186-188 for different look and feels, 313 constructors, 185-186 image files needed by, 776 data model, 185 initialValue argument, 294-295 event handling, 190-191 input area, 290 example, 166 look and feel, 312-315, 313 look and feel, 191-192 message area, 290,308-311 methods,186-187, 189 message argument, 292-293 objects, 189 message text formatting, 306 properties,189-190 message types, 298-300 separators, 192 messageType argument, 293 setPopupVisible(), 177 methods,295,298,300 UIResource elements, 192 options argument, 294 UML relationship diagram, 186 optionType argument, 293-294 JMenuBar parts, 289 about,165,170, 171-172 position constants, 298 constructor, 172-173 and ProgressMonitor, 319 examples, 166,594 properties,304-312,308,309,310 glue in, 388, 389 with PropertyChangeListener, 312 and JLayeredPane, 255-256 PropertyChangeListener support constants, layout manager, 177 312 look and feel, 175-177,176 static create and show methods, 300 methods, 172,388 with string array, 307 properties, 174-175 UIResource elements, 314 selection model, 177 UML relationship diagram, 291 UIResource elements, 175 using factory methods, 291 UML relationship diagram, 172 using static creational methods of, 272 JMenultem using to create an internal frame, 277 abou~ 165,170,178 using with }Button, 311 constructors, 178-179 using with }Slider, 309 event handling, 181-184 examples, 166, 600 in }Menu or JPopupMenu, 42 look and feel, 184-185 objects, accelerators for, 196 properties, 180-181 selection sequence diagram, 182

842 Index

JPanel JRadioButton about, 122 about, 110, 148 constructors, 122-123 creating, 148-150 default opaque setting, 125 data model, 148 to display pop-ups, 198 default data model for, 128 look and feel, 126 grouped with RadioButtonUtils, 153 methods, 124-125 list of text actions, 591 as a renderer, 636 look and feel, 162 restrictive focus cycle, 58, 59 objects, 154 tooltip text in, 98 parent, 131 UIResource elements, 126 properties, 150 JPasswordField selection event handling, 153-161 about, 10,521,566-569 UIResource elements, 162 additional, for TextAction, 591 UML relationship diagram, 149-150 constructors, 567-568 use ofButtonGroup, 148, 150-152 examples, 11, 569 vs. JCheckBox, 148 look and feel, 569 JRadioButtonMenultem methods, 539 about, 110, 209 properties, 568 and ButtonGroup, 211 UIResource elements, 569 constructors, 209-211 use ofJTextComponent methods, 532-539 default data model for, 128 JPopupMenu event handling, 211 about, 165, 194 example, 12,212-214 Action objects and, 42 icon for, 209-211 Action support, 46 look and feel, 211 adding menu items to, 195-196 properties, 211 constructors, 195 UIResource elements, 212 displaying, 196-197 UML relationship diagram, 210 event handling, 197, 199 JRootPane examples, 166,201-203,553-554 about, 255-256 and JMenu, 185, 188 containment diagram, 257 layout manager, 188 creating, 257 look and feel, 199, 200 defaultButton, 119 menu icons and, 167 glass pane, 256, 257,258 methods, 195, 196, 197 and JPopupMenu, 198 properties, 198-199 main component container, 259 selection model, 177 methods, 258 separators, 192 properties, 257-258 UIResource elements, 200 JScrollBar UML relationship diagram, 194 about, 427-429 JPopupMenu.Separator, 201 BoundedRange properties on a, 425 JPopupMenuShower, 197, 201 constructors, 429-430 JProgressBar data model, 431 about, 446-447 dual , 433 constructors, 448-449 event handling, 430-432 creating, 451 horizontal, 428, 429 data model, 447 and JScrollPane, 408 event handling, 454-455 look and feel, 434 examples, 11,452-453,454 methods, 433 labeling, 450 orientation, 429-430, 433 look and feel, 455-456 properties, 428, 433-434 methods, 449, 450 tracking JTextfield width with, 457 orientation, 448 U!Resource elements, 435 and ProgressMonitor, 316 UML relationship diagram, 429 properties, 448, 449-454 vertical, 428, 429 sample components, 447 source code, 450 stepping along, 450-454 UIResource elements, 456 UML relationship diagram, 447 843 Index

JScrollPane JSpli~e about,383,407-409 about, 383, 390 constants, 409,410 componentchangeswithin,393-396 constructors, 409-411 constants, 390, 396-398 with a corner component, 415 constructors, 390--392 example, 408 dividers, 394-396, 398, 400 headers and corners, 414-415 examples, 14,391,671,677 and JComboBox, 498 and JScrollPane, 396 andJlist, 476-479 and JTextArea, 396 and JScrollBar, 408 look and feel, 399 JScrollBar within a, 427 methods,393-394 withinJSpli~e,396 orientation, 390, 392, 393 andJTextArea, 571,572 properties,390--396,397 JTe~e within, 584 oneTouchExpandable, 395 layout manager, 381, 382 PropertyChangelistener, 396-398 look and feel, 416, 417 resizing components properties,411,412-416 UIResource elements, 399 row and column headers, 417 JTabbedPane Scrollbar policies, 408, 410, 415 about, 383, 400-401 UIResource elements, 416 constants, 402 UML relationship diagram, 409 constructors, 401 JScrollPane.ScrollBar, 408 default panel title, 403 JScro11PaneToTop~on,415-416 example, 14 JSeparator and JColorChooser, 326 about, 165, 192 look and feel, 406 constants, 193 methods, 402-404 constructors, 192-193 properties,404-405 example,13 sample screen, 400 examples, 166 selection model, 177 look and feel, 194 tab placement options, 402 menu icons and, 167 tab selection listening, 405-406 methods, 201 UIResource elements, 407 properties,193-194 UML relationship diagram, 401 UIResource elements, 194 JTable JSlider about, 689-691 about, 436 column headers, 690, 695--696, 707 client properties, 446 column resizing, 699-702 constructors, 437-438 constructors, 692--694 with a custom icon, 446 with custom renderer, 704-705 data model, 436 data model, 715, 724 dictionary, 443 default editors, 735 display of tick marks within, 440-442 default renderers, 100, 711, 712 event handling, 438-439 editors, 642, 735-743 example, 11,441 event handling, 705 filled and unfilled track, 445 event listeners, 726-728 and JOptionPane, 308-311 examples, 11,689,755 labels, 436, 442-444 fixed columns, 709-711 look and feel, 444-446 and JScrollPane, 414 methods,439,440-441,442,443 look and feel, 705-706 orientation, 437 methods,692,694 positions and tracks, 445 properties,696-702,724 properties,439-440,442 renderers, 702-705,711-712 sample components, 436 resizing column modes, 700 UIResource elements, 445 and Scrollable, 694--696 UML relationship diagram, 436 scrolling support, 411 vertical, 438 selection modes, 698 JSlider.isFilled, 446 sorting of elements, 715-724 , 705

844 Index

JTable (continued) JTextField (continued)

UIResource elements, 706 look and feel, 566, 567 UML relationship diagram, 691 properties, 530-532, 559 without column headers, 696 tracking width with jScrol!Bar, 457 without JScrol!Pane, 694 UIResource elements, 566 JTableHeader UML relationship diagram, 527 about, 690, 732 use of JLabel mnemonics, 529-530 constructors, 732-733 use ofJTextComponent methods, 532-539 example, 691 JTextFieldSample, 562, 563-565 look and feel, 734 JTextPane objects, 732 about, 10,521,582-583,589,601-602 properties, 733 constants, 596 tooltips, 733-734 constructors, 583-584 UIResource elements, 734 creating multi-attributed text for, 606 JTextArea data model, 602, 604 about, 71-72,73,521,570 interfaces, 582-583 constructors, 571-572 within JScrol!Pane, 584 event handling, 574 JTextComponent methods with, 532-539 examples, 487, 488-489 look and feel, 584-585 and JScrol!Pane, 571, 572 properties, 584 within JSplitPane, 396 sample, 585 and JTextField tab stops for, 612 example, 537 UIResource elements, 584-585 listing contents to, 464 UML relationship diagram, 583 look and feel, 57 4, 575 JToggleButton properties,572-574 about, 10, 131-132 sharing a Document, 75 configurable options, 134 support of undoable operations, 784 constructors, 132-133 UIResource elements, 574 data model, 128 UML relationship diagram, 570 examples, 11, 127 use of JTextComponent methods, 532-539 andJCheckbox, 139 JTextComponent look and feel, 138 about, 521, 523 methods, 134 Action UML relationship diagram, 591 notification sequence diagram, 136 CaretListener with, 554-556 objects, 127 event handling, 525 properties, 133-134 example, 594 sample components, 131 methods,527,532-539,553,590 selection event handling, 134 properties, 523-526, 532, 537 subclasses, 128, 150 registering KeyStroke to, 556 U1Resource elements, 138-139 scrolling support, 411 UML relationship diagram, 132 subclasses, 527 use of AbstractButton properties, 134 JTextComponent.KeyBinding, 558 See also JCheckbox JTextField JToggleButtonMenultem, 215-220 about,521,527-528 JToggleButton. ToggleButtonModel and BoundedRangeModel, 457 class hierarchy, 127 constants, 596 definition, 127 constructors, 528-529 JToolBar data model, 527 about, 165, 220 editor for JTable, 735 Action objects and, 42 editor for JTree, 644, 646 Action support, 46 event demonstration, 562, 563-565 adding components to, 221-222 event handling, 558-565 component borders, 224 example, 569 constants, 220, 222 extra TextAction, 591 constructors, 220-221, 226 andJComboBox,497,509 default, 220 and JTextArea event handling, 223 example, 537 examples, 12,166,224-226

845 Index

JToolbar (continued) Niewport (continued)

layout manager, 222 layout manager, 382, 417, 418 look and feel, 223-224 objects, 408 methods,221-222,226, 768 optimized drawing, 81 orientation, 220 properties,418-419 properties,222-223 UML relationship diagram, 417 removing components from, 222 }Window separators, 192 about, 255, 267 UIResource elements, 224 constructors,267-268 UML relationship diagram, 221 and JPopupMenu, 198 undo/redo buttons, 784, 786 properties, 268 JToolBar.isRollover, 224 protected methods, 268 JToolBar.Separator, 226 and RootPaneContainer, 258 JToolTip UML relationship diagram, 267 about, 93 creating, 93-94 customized objects, 945-96 example, 12 K look and feel, 96-97 properties, 95 keyboard events, handling, 40 }Tree keyboard navigation support, 171, 179 about, 619-621 KeyEvent with altered default renderer, 634 MenuKeyEvent, 183 client properties, 631-632 methods,34,60,61,544 creating, 622-625 VK_* constants, 51, 115, 180 creating a custom renderer, 635-639 Keylistener data models, 622, 677, 679 about, 34 default renderer, 100 for focus traversal management, 60 editors, 641-662 with }Frame events, 265 examples, 12,619,625,626,631,645,648, with TfextField events, 559-560 669 KeyEventcombo,523 expansion event handling, 685-687 objects, registering to components, 49 icons,630,633,645,647 for restricting text input, 544 with lazy values, 762 with Swing text components, 558 look and feel, 628, 629, 630-632 when to use, 590 making editable, 644 Keymap,40,42, 72,522,556-558 methods, 640 example,557-558 objects, 671 and TextAction, 590 properties,627-628,634,642 keyPressedQ (KeyEvent), 61 rows versus levels, 626 KeySelectionManager, 498, 503 and Scrollable, 625-626 KeyStroke scrolling support, 411 about, 40, 49-50 tooltips,99,639-641,641 creating a, 50-51 tree renderer, 635 mapping to TextAction, 590 UIResources elements, 629-630,631 objects, 53, 556 UML relationship diagrams, 620-622 registering a, 51-53 and Vector, 665 to JTextComponent, 556 with and without angled lines, 85 registration conditions, 50 working with nodes of, 662-667 specifying as text string, 51 JTree.DynamicUtilTreeNode, 619, 670 keystroke masks, 181 ]Tree.lineStyle, 631, 632 keystrokes NiewPort associating with actions, 590 about, 383 binding to text· actions, 522 Niewport removing from keymap, 557-558 about,89,407,416-417 KeyStrokeSample, 52 borders, 418 KeyTextComponent, 35, 36 constructor, 418 KeyTextTester, 36 example, 419-422 knob. See thumb and JScrollPane, 414-415 846 Index

L listeners. See event listeners ListModel about,459-460,473 Label, 99 class hierarchy diagram, 460 Labe!Accessory, 360--361 data model, 459 LABELED_BY_PROPERTY, 103 event listening, 463-469 LabelHeaderSample, 731-732 for JComboBox, 498 labels See also AbstractListModel Box container, 385 See also ComboBoxModel button, 464 ListPlafs, 748 }Button, 46 ListProperties, 756--758 JMenultem, 178,179-180 ListSelectionEvent, 487-490 JProgressBar, 450 ListSelectionListener }Slider, 436, 442-444 withJListevents,487-490 underlined character in, 53, 114 with ListSelectionModel, 699 See also text labels objects, 485, 490 LabelSample, 530 ListSelectionModel, 473,485-486,689,690,691, last path component, 684 698-699,724 LayeredHighlighter, 550 LoadSave,534-536 LayeredHighlighter.LayerPainter, 551 localization,314-315 layout managers locate() (FindAction), 599 and alignments, 101 locationTolndex() (JUst), 489 axis point, 376 log messages, 68 resource book about, 370 LookAndFeel Swing use of, 14 about, 745-746 See also BoxLayout auxiliary, 781 See also ScrollPaneLayout changing current, 748-752,807 LayoutManager class hierarchy diagram, 74 7 changing for JTabbedPane, 405 components used by, 303 class hierarchy diagram, 369 creating a new, 772-777 JPanel,123 customizing current, 752-772 withJTextArea,571 example, 749 vs. Container, 400 F8 key and, 394 LayoutManager2, 371, 376 and FileView, 362 LazyDiamondlcon, 760--761 getting info about, 747-748 LazySaLnple, 761-762 getting original default, 758 LazyValue, 760,762 image files, 774-775 leader characters, 589, 615 key class diagram, 746 leaf nodes, 619,623,648-649,650 listing installed classes of, 74 7-748 LeafCellEditor, 648-649 methods, 760 LineBorder multi-selection of files by, 354 about, 237 objects, 781 constructors, 238 predefined creating. 238 overriding default settings, 752 example, 238 placement of tick marks, 440 factory methods, 238 UIResource elements, 808-822 methods,238-239 properties, 746--7 4 7 properties, 239 subclassing, 772-777, 776 subclassing, 239 See also names of specific components List, 8-9 lookup tables ListActions, 592-594 AbstractAction, 45 ListCellRenderer, 473,480-482,501,736--737 }Label for }Slider, 442-443 example,482-484 lowestLayer() (JLayeredPane), 260 with JComboBox, 498 ListDataEvent,463,464,476 ListDataListener with }Combo events, 508 with ListModel events, 463-469 management of, 460 objects, 459, 461, 464 847 Index

M messages (continued) pop-ups with, 298 MacLookAndFeel on a non-Macintosh, 773-776 undo-redo operation, 786 main() messageType,293 DuallistBox, 493, 496 MetalComboBoxUI, 516 JComboBox, 472 MetalLookAndFeel, 747, 776-777 UndoableDrawingPanel, 804 MetalTheme, 777-779 makelcon() (LookAndFeel), 760 MetalToolBarUI, 769 MatteBorder, 237, 243-245 Metalworks system demo, 780, 781 MDI (multi-document interface), 13, 255, 275, MIME-types, 576, 578 276 mnemonics MediaTracke~ 108 AbstractButton, 115 menu accelerators. See accelerators defined, 114 menu bars examples, 103, 166 adding and removing menus, 17 4 JLabel, 525, 529-530 altering appearance of, 174 listening for press of, 183 borders, 176 menu item, 178, 179-180 Swing applet, 273 using, 53 menu choices, creating, 166-170 modality, 269, 304, 315 menu class hierarchy diagram, 171 pop-up, 331 menu item renderer, 181 Model-View-Controller. See MVC (Model-View- menu items Controller) disabling, 17 4 modellndex argument, 729 with a grid layout, 188 modelToView() (JTextComponent), 527, 553 removing, 187 modifier masks, 180 menu shortcuts, 53 ModifyModelSample, 464, 465-469 MenuDragListener with JMenultem events, MotifLookAndFeel, 747 184-185 mouse navigation support, 171 MenuDragMouseEvent, 184 MouseEvent MenuDragMouseListener, 184 double-click, 489 MenuElement, 171, 181,214,215-220 MenuDragMouseEvent, 184 MenuEvent, 191 modifiers, 29 MenuKeyEvent, 183 and popup menus, 197 MenuKeyListener with JMenultem events, MouselnputAdapter, 25 183-184 MouselnputListener, 220 MenuListener, 184 methods, 29 with JMenu events, 191 MouseListener, 25, 54, 265, 723 objects, 191 MouseMotionListener, 25, 265 menus mousePressed() (SwingUtilities), 29 activating invisible items from, 53 moveCaretPosition() (JTextComponent), 527 adding to menu bars, 173 moveDot() (Caret), 552 creating, 166-170 moveToBack() (JLayeredPane), 260 disabling, 17 4 moveToFront() (JLayeredPane), 260 key and mouse events over, 215, 220 MoveViewSample, 420-422 removing from menu bars, 174 MultiKeySelectionManager, 504-505 separator bars, 13, 180, 187, 192, 195 MultiLookAndFeel, 781 submenus, 165 multithreading, 64-68, 450 tear-off, 185 MutableAttributeSet, 582, 589, 602, 605, 611 using action objects with, 188--189 MutableComboBoxModel, 75,460,471 vertically arranged, 173, 175-177 MutableTreeNode, 619,662,663-664 MenuSample, 167-170 MVC (Model-View-Controller) menuSelectionChanged() (MenuElement), 215 about, 15 MenuSelectionManager, 184, 214 bounded component data model, 425-426 MenuShortcut (AWf class), 181 communication mechanism, 71 message types, JOptionPane, 298--300,312 UI delegates for components, 745 messages way of listening, 430 displaying multi-line, 305 MyMac, 773-774 localized, 314 MyMetal, 776-777 multi-line, 307 848 Index

N Imagelcon, 107, 108 Insets,233,236,251 Integer, 296 NamedVecto~624,625,637,665 JButton, 294 NarrowOptionPane, 305-306, 307 I Component, 80-82 NextComponentSarnple, 61-62 Jlnterna!Frarne, 285 nodeChangedO (DefaultTreeModel), 678 JMenu, 189 nodes JMenuitem, 196 about, 619 JOption message argument, 292-293 check box, 682 JRadioButton, 154 dragging and dropping, 671--677 JTableHeader, 732 editable, 656 JToo!Tip, 94-96 information stored at, 662 JTree, 671 keys used to select multiple, 680 Keylistener, 49 nonleaf, 651 KeyStroke, 53, 556 root, 669 listDatalistener, 459,461,464 rows of, 626 listSelectionListener, 485, 490 shared ancestor of, 668 LookAndFeel, 781 specifying whether children allowed, 664 Menulistener, 191 nodesChanged() (DefaultTreeModel), 678 Object, 669 nodeStructureChanged() (DefaultTreeModel), PopupMenulistener, 199 678 ProgressMonitorlnputStrearn message nodesWerelnserted() (DefaultTreeModel), 679 argument, 322 nodesWereRemoved() (DefaultTreeModel), 679 registering PropertyChangelistener, 31 NORMAL,264 Runnable, 40, 65 notify-field-accept, 591 sequence diagrams of interactions among, 5 Number, 711 StateEdit, 783, 803 Number.class, 711 StateEditable, 803 Style, 602 TableColurnn, 725, 729 TableColumnModelEvent, 726 0 TableModelListener, 707 TabStop, 612 Object, 87, 510, 669, 681, 684 TextAction, 72, 594, 598, 600 objects Timer, 67 Action, 188-189, 589,596, 786 TitledBorder, 246 Actionlistener, 797 ToggleButtonModel, 128 AttributeSet, 611 Transferable clipboard, 536 AWT Window /Swing replacement treated as strings, 510 components table, 10 tree node, 662 Book, 637 TreeModellistener, 677, 678 CellEditorlistener, 642, 655, 739 TreePath,656,681,684 checking equality of, 238 TreeSelectionlistener, 682 Color, 326, 511, 512, 759 UIDefaultsActiveValue, 745 Component, 408, 510 UIDefaults.LazyValue, 745 confirm pop-ups, 302 UIManager.LookAndFeellnfo, 754 container, 122 undo/redo capabilities, 791 delegate, 72 undoable, 802 Dimension, 389 UndoableEdit, 7,96, 799, 804 Element, 544 UndoableEditListener, 799, 803 EtchedBorder, 242 URL,576 event listeners, 113 use~662,664,666,671 File, 355 Vector, 692 FileChooserUI, 361 Observer design pattern, 22, 30 high-level container, 9-10, 79-80, 255 See also MVC (model-view-controller) Highlighter.Highlight, 550, 551 opaque borders, 231,233,235 HyperlinkEvent, 580 opaque components, 404 Icon, 730 opaque compound borders, 245 Image, 106-107 opaque renderer component, 481

849 Index

option pop-ups, 298 pop-up windows (continued) OptionPaneUtils, 296-298,305,308-311,310 options, 294 JColorChooser, 329-331 Options submenu example, 167 JComboBox,500-501,502 optionType,293-294 JFileChooser within, 353-354 outline drag mode, 285 JOptionPane in, 298-304 OvalPanel, 124-125,396 message with two JLabel components, OverlayLayout, 376-381,377,378,381 323-324 OverlaySample, 378-381 Swing support for, 13 titles for, 295 for undo/redo operation, 786 PopupComboSample, 516-517 p PopupMenuEvent, 199 PopupMenuListener, 199 PopupSample, 202-203, 553-554, 556 paint() (JComponent), 64, 80, 81 postEditO (UndoableEditSupport), 797 paintBorderO postOrderEnumeration() AbstractBorder, 235-236, 251 (DefaultMutableTreeNode), 669 Border interface, 231,232 preOrderEnumeration() }Component, 80, 81 (DefaultMutableTreeNode), 669 paintChildrenO (JComponent), 80, 81 preview panel, JColorChooser, 334-335 paintComponentQ (JComponent), 80-81 printDescendents() (DefaultMutableTreeNode), paintlconQ Ocon), 104, 208, 338 669 paintlmmediately() (IComponent), 82, 88 PrintlielloAction,43 PllLET1r.E_IJ\Y1ER,282 println statements in listener, 580 Panel, 98, 122, 198 processKeyEvent() (MenuElement), 215 panels processMouseEvent() (MenuElement), 215 JColorChooser, 336-347 progress bars multiple, 326, 400 advancement along, 318 for pop-up windows, 289-290 displaying in a , 454 See also tabs filling in reverse direction, 454 parentComponent argument, 316 labeling, 450 password entry, 10, 521, 556-569 orientation of, 448 paste() stepping along, 450-454 JPasswordField, 539 ProgressBarStep,452-453,454 JTextComponent, 527,537 ProgresslnputSample, 323-324 pathByAddingChildQ (TreePath), 684 ProgressMonitor PIJ\F architecture, 8, 745-782 about,289,315-316 PlainDocument, 73, 522, 527, 543 constructor, 316 PlainView, 73 example, 319-321 platform-specific file information, 361 look and feel, 319 platform-specific mnemonics, 180 properties, 316, 318, 319 architecture, 8, 745-782 sample, 315 polygon example, 798-799, 803 sample frame, 319 pop-up icons using,316-317 JComboBox, 516 ProgressMonitorHandler, 319-321 JOptionPane, 777 ProgressMonitorlnputStream pop-up menus, listening for, 191 about, 289, 322 pop-up messages constructo~322-324 displaying, 93 pop-up,323 Swing support for, 12 property, 325 pop-up windows UML relationship diagram, 322 centering using, 323-324 over components, 295 ProgressUI, 447 on screen, 301 closing, 295 color editor, 742 for Frame information, 269 getting user input from, 289

850 Index properties properties (continued) AbstractAction, 44 AbstractButton, 112, 116 DefaultTableColumnModel, 725 actionCommand, 120 DefaultTableModel, 714 deprecated label, 112 numRows, 714 disabledlcon, 115 DefaultTreeCellRenderer, 633 disabledSelectedlcon, 115 DefaultTreeSelectionModel, 681 equivalenttext, 112 displaying a list of, 755 icon,115 DocumentEvent pressedlcon, 115 length, 549 rolloverlcon, 115 offset, 549 rolloverSelectedlcon, 115 event listeners for, 91 selectedlcon, 115 getting and setting values of, 64 text, 120 Imagelcon, 108 AbstractDocument, 543 imageLoadStatus, 108 bidiRootElement, 543 inherited methods of, 190 defaultRootElement, 543 JButton, 118 document, 542 defaultButton, 118, 119 length, 542 JCheckBox, 140 AbstractTableModel JCheckBoxMenultem, 205, 207 columnCount, 714 checklcon, 207 rowCount, 714 JColorChooser, 333 AbstractUndoableEdit chooserPanels, 347 presentationName, 793 color, 333 redoPresentationName, 793 previewPanel, 334,347 ancestor, 91 JComboBox, 500 BoundedRangeModel, 425 editable, 508 extent, 428, 437 lightWeightPopupEnabled, 500-501 valuelsAdjusting, 426,427,431 maximumRowCount, 500 Box, 386 popupVisible, 500-501 layout, 386 JComponent, 85-87 buttons accessibleContext, 89 defaultCapable, 119 alignmentX and alignment¥, 88 Caret, 552 autoscrolls,89 blinkRate, 552 background/foreground, 88 dot, 552 border, 88 magicCaretPosition, 552 bounds, 87 clientproperties,84-85 colorModel, 88 ColorSelectionModel componentCount, 87 selectedColor, 328-329 componentOrientation, 88 87 Component components, focusTraversable, 55, 57 cursor, 89 selectionBackground, 697 debugGraphicsOption, 88 selectionForeground, 697 displayable, 89 81 CompoundEdit double buffering, inProgress, 793 doubleBuffered, 88 dropTarget, 89 DefaultButtonModel, 114 selectedObjects, 114 enabled, 89 57, 58, 87 DefaultCellEditor, 646 focusCycleRoot, focusTraversable, 87 cellEditorValue, 646 font, 88 DefaultComboBoxModel, 471 graphics, 88 DefaulilistModel, 463 height, 87 DefaultListSelectionModel, 486 inputContext, 88 isSelectedlndex, 487 88 selectionEmpty, 487 inputMethodRequest, DefaultMutableTreeNode, 666--667 insets, 88 userObject, 639, 666 layout, 88 userObjectPath, 666 lightweight, 89 DefaultStyledDocument, 604 locale, 88 styleNames, 604 locationOnScreen, 87 851 Index

properties (continued) properties (continued)

managingFocus,57,58,61,87 }Layered, 260 maximum Size, 88 JLayeredPane, 262 minimum Size, 88 optimizedDrawingEnabled, 262 name, 89 JUst, 475-476 nextFocusableComponent, 57, 61-62, 87 anchorSelectionlndex, 476 opacity, 81 cel!Renderer, 480 opaque, 88 firstVisiblelndex, 4 79 optimization, 81 fixedCel!Height, 4 77 optirnizedDrawingEnabled, 88 fixedCel!Width, 477 paintingTile, 88 lastVisiblelndex, 4 79 parent, 87 leadSelectionlndex, 4 76 preferredSize, 88 maxSelectionlndex, 476 registeredKeyStrokes, 89 minSelectionlndex, 4 76 requestFocusEnabled, 57, 87 preferredScrollableViewportSize, 4 77 rootPane, 87 prototypeCel!Value, 477 showing, 89 selectedlndex, 476,489 size, 87 selectedlndices, 4 76, 487 toolkit, 89 selectedValue, 476,489 toolTipText, 89 selectedValues, 476,487 topLeve!Ancestor, 87 selectionMode, 486 treelock, 89 setVisibleRowCount, 477 UIClassiD, 89 visibleRowCount, 476 valid, 89 JMenu, 190 validateRoot, 89 accelerator, 189 visible, 89 delay, 190 visibleRect, 89 tearOff, 190 width, 87 JMenuBar, 175 JDesktopPane, 284 helpMenu, 174 allFrarnes, 284 selected property of, 17 4 dragMode, 285 JMenultem, 180 }Dialog, 271 accelerator, 180 defaultCloseOperation, 271 component, 180 locationRelativeTo, 271 subElements, 180 JEditorPane, 578 JOptionPane, 305 contentType, 578 inputValue, 305, 308 page, 578 maxcharactersPerLineCount, 305 text, 578 message,306-308 JFileChooser, 355 options, 310 dialogType, 355 selectionValues, 305 directorySelectionEnabled, 359 value, 305 fi!eHidingEnabled, 358 wantslnput, 305, 309 fileSelectionEnabled, 359 JPasswordField, 568 fi!eSelectMode, 359 echoChar, 568 JFrame,263 password, 568 defaultCloseOperation, 263-264, 266 JPopupMenu, 198 layout, 263-263 lightWeightPopupEnabled, 198, 199 JinternalFrarne, 277 title, 199 constrained properties, 278 JProgressBar, 449 isPallete, 281 border, 449 jMenuBar, 278 borderPainted, 449 menuBar, 278 extent, 448 JLabel, 101 JRadioButton, 150 displayedMnemonic, 103 JRadioButtonMenultem, 211 horizontalAlignment, 100, 101 actionCommand, 212-214 icon, 100 JRootPane, 257 labelFor, 103, 525 defaultButton, 119 text, 100 focusCycleRoot, 258 verticalAlignment, 101 menuBar, 258 852 Index properties (continued) properties (continued)

validateRoot, 258 highlighter, 525 JScrollBar, 434 inputMethodsRequests, 524 blocklncrement, 428 keymap,525 unitlncrement, 428 margin, 525 JScrol!Pane, 413 opaque, 525 columnHeaderView, 415 preferredScrollableViewportSize, 525 layout, 412 scrollableTracksViewportHeight, 525 rowHeaderView, 415 scrollableTracksViewportWidth, 525 view, 411 selectedTextColor, 524-525 viewportView, 411 selectionColor, 524-525 }Separator, 193 selectionEnd, 525 orientation, 193 selectionStart, 525 JS!ider, 440 text, 524 snapTo Ticks, 442 JTextField, 530-531 JSplitPane, 392 actionCommand, 559 continuousLayout, 390-392, 396 horizonalA!ignment, 531, 532 dividerLocation, 394, 398 horizontalVisibility, 531 lastDividerLocation, 396, 398 scrol!Offset, 531 oneTouchExpandable, 395 JTextPane, 584 JTabbedPane, 404 JToggleButton, 133 selected Component, 404 JToolBar, 222 selectedlndex, 404 borderPainted, 222 tabRunCount, 404 orientation, 222 }Table, 696---697 JToolTip, 95 autoCreateColumnsFromModel, 724 JTree, 627 cel!SelectionEnabled, 698 cellRenderer, 628 columnSelectionA!lowed, 698 editable, 642 gridColor, 698 flxedRowHeight, 628 intercel!Spacing, 698 largeModel, 628 rowSelectionA!lowed, 698 lastSelectedPathComponent, 628 selectionModel, 699 leadSelectionRow, 628 showGrid, 697 maxSelectionRow, 628 JTableHeader, 733 minSelectionRow, 628 updateTablelnRealTime, 733 rootVisible, 628 JTextArea,572 rowHeight, 628, 634 columns, 572 selectionPaths, 628 font, 572 showsRootHandles, 628 lineCount, 573 visibleRowCount, 628 lineWrap, 573 }Viewport, 418 managingFocus, 573 backingStoreEnabled, 418 preferredScrollableViewportSize, 572 eventSize, 418, 419 preferredSize, 572 insets, 418 rows, 572 view, 418 scrollableViewportWidth, 572 viewPosition, 418, 419 tabSize, 573 viewRect, 419 wrapStyleWord, 573 viewSize, 418, 419 JTextComponent, 524 JWindow, 268 actions, 525, 537 UneBorder, 239 caret, 525 UstDataEvent, 463 caretColor, 524-525 ListSelectionEvent, 487 caretPosition, 525 valuelsAdjusting, 487 disabledTextColor, 524-525 LookAndFeel, 746 document,524,532 defaults, 746 editable, 525 native, 747 enabled, 525 supportedLookAndFeel, 747 focusAccelerator, 525 Meta!, 777-779 focusTraversable, 525 controlTextFont, 777

853 Index

properties (continued) PropertyChangelistener with AbstractButton events, 116-117 menuTextFont, 777 and BoundedRange~odel, 426 subTextFont, 777 in JButton example, 46, 47, 49 systemTextFont, 777 with ]Component events, 89-91 userTextFont, 777 with JFileChooser, 359 windowTextFont, 777 with Jinterna!Frame events, 278-279 Progress~onito~318 with JOptionPane events, 312 millisToDecideToPopup, 316,318,325 with JSplitPane property changes, 396-398 millisToPopup,316,318 Observer pattern, 30 progress,318,319 using as an observer, 30-33 Progress~onitorlnputStream, 325 PropertyChangeSupport, 30, 33, 796 Repain~anager, 82 PropertySplit, 397-398 SimpleAttributeSet, 606 publish-subscribe model, 23 TableColumn, 730 pull-down lists, 497 TableColumn~ode!Event, 726 put() Table~odelEvent, 715 Hashtable, 803 column, 715 UI~anager, 83, 753 firstRow, 715 putClientProperty() (]Component), 84,631,765 TabStop, 612 putDefaults() (UIDefaults), 755 leader, 615 putProperty() (AbstractDocument), 542 Timer, 68 putValue() (Action), 45 coalesce, 68 delay, 68 initia!Delay, 68 repeats, 68 Q running, 68 TidedBorder, 248 QUESTION_~ESSAGE pop-ups, 301, 302 ToolTip~anager, 97-99 dismissDelay, 98 initia!Delay, 98 lightWeightPopupEnabled, 97-99 reshowDelay, 98 R TreePath, 684 lastPathComponent, 685 radio buttons, 12 parentPath, 685 RadioButtonSample, 212-214 path, 684, 685 RadioButtonUI, 148 pathCount, 685 RadioButtonUtils UI~anager, 754 class definition, 159-161 crossPlatformLookAndFeelClassName, grouping JRadioButton components with, 754 153 defaults, 753, 754 methods, 150, 155, 156 lookAndFeelDefaults, 754 RangeSample, 547-548 systemLookAndFeelClassName, 754 read() (JTextComponent), 527,532,533 UI~anager.LookAndFeellnfo, 754 Receiver, 790 UndoableEditEvent Rectangle, 553 edit, 796 redo() See also bound properties AbstractUndoableEdit, 801 See also client properties CompoundEdit, 793 See also PropertyChangelistener Undo~anager, 784,791,792,796 See also UIResource properties Redoable state, 793 Properties~eta!Theme, 781 registerComponent() (Too!Tip~anager), 98 property-sheet, 400 registerKeyboardAction() (KeyStroke), 49,556 property-sheet motif, 14 relationship notation in U~l diagrams, 4-5 PropertyChangeEvent,278 reload() (DefaultTree~odel), 679

854 Index remove() s Container, 174, 187, 196 Document, 544-545 JPopupMenu, 196 screen layout with Swing, 14-15 JTabbedPane, 404 See also display JToolBar, 222 Screen redraws, reducing, 249 removeAll() (JTabbedPane), 404 Scrollable,411-412,525,619 removeCellEditorListener() (CellEditor), 654 Scrollbar, 11 removeChooserPanel() (JColorChooser), 336,347 Scrollbar policies, 408, 410, 415 removeElement() scrollbars DefaultListModel, 462, 464 arrow buttons, 428 MutableComboBoxModel, 471 horizontal and vertical, 408 removeElementAt() (MutableComboBoxModel), JScrollPane,423,427 471 theme settings for, 779 removeListSelectionListener() (}List), 487 ScrollBarSample, 432-433 removeNodeFromParent() (DefaultTreeModel), ScrollBarUI, 428 678 scrolling updates, 419 removeNotify() (}Component), 91 ScrollOffset, 531 removeSelectedlnterval() (}List), 490 ScrollPane,407,625 removeTabAt() (JTabbedPane), 404 ScrollPaneLayout, 381, 382, 408, 410, 412-414 removeUndoableListener() scrollPane.setColumnHeaderView(null), 696 (UndoableEditSupport), 797 scrollPathToVisible() (JScrollPane), 626 remove Update() (DocumentListener), 548 scrollRowToVisible() (JScrollPane), 626 removeXXXListener(), 22 select() (JTextComponent), 527 RendererSample, 704-705 selectAll() repaint() (}Component), 66, 80 ComboBoxEditor, 510 RepaintManager JTextComponent, 527 about, 80 SelectingCheckBox, 145-146 methods, 83 SelectingComboSample, 506--508 properties, 82 SelectingListSample, 488-489 replaceSelection() selection models (JTextComponent), 527 SingleSelectionModel, 172 requestFocus() (Component), 53, 54,55 See also data models resetChoosableFileFilters() (JFileChooser), 358 selection path, defined, 184 resetToPreferredSizes() (JSplitPane), 394 selectionForKey() (KeySelectionManager), ResizeTable, 701-702 503--505 restart() (Timer), 67 selectWithKeyChar() (JComboBox), 505 restoreState() (StateEditable), 802, 803 separator bars. See }Separator ResultSet, 462-463 sequence diagrams, 5 revalidate() setA!ignmentXO (}Component), 371 }Component, 66, 82, 89 setA!ignmentYO (}Component), 371 JRootPane, 258 SetBackground() (UIManager), 758 RGB panel, 327, 336 setBorder() Rich Text Format (RTF), 576 }Component, 229 root, 619 Niewport, 418 root node, 670 setBorderPainted() (JProgressBar), 449 RootLayout,255,256 setBottomComponent() (JSplitPane), 393 RootPaneContainer, 255--288, 257, 258, 262 setCellRenderer() (TreeCellRenderer), 633 roundedCorners (variable), 239 setChooserPanels() RoundedLineBorder, 239 (AbstractColorChooserPanels), 336, ROW_HEADER, 410, 414 345 RowMapper, 620, 681 setColor() (AbstractColorChooserPanel), 340 setCorner() (JScrollPane), 415 rows setCurrentManager() JList, 476, 477 mapping to paths, 681 FocusManager, 63 Runnable, 65 RepaintManager, 82 Runnable objects, 40 setDefaultLightWeightPopupEnabled() (JPopupMenu), 199 setDisplayedMnemonic() (}Label), 529

855 Index

setDividerLocationO (JSplitPane), 394 setToolTipWindowUsePolicy() (non-existent), 98 setDocumentO (Document), 545 setTopComponent() (JSplitPane), 393 setEditable() (JEditorPane), 581 SetUI() (UIManager), 769 setEnabledO (AbstractAction), 189,251 setValue() setExtentO (JScrollBar), 433 JScrollBar, 433 setExtent() (]Slider), 439 }Slider, 439 setFileFilterO (JFileChooser), 358 setValueAtO (]Table), 692 setHelpMenu() (JMenuBar), 388 SharedDataSample,518-519 setlmagelcon() (UIManager), 769 sharedlnstance() (Too!TipManager), 97 setlnverted() (JSlider), 445 ShareModel, 7 4 setltem() (ComboBoxEditor), 511 Shift-CTRL, 574 setJMenuBar() (multiple classes), 172, 173 shouldSelectO (CellEditor), 657 setKeymap() (JTextComponent), 590 show() (JPopupMenu), 197 setLabe!For() (JLabel), 529 ShowAction,189,224 setLabelTable() (JS!ider), 442 showConfirmDialog() (JOptionPane), 301 setLayer() (JLayeredPane), 259 showDialogO (JColorChooser), 329-330, 340, 353, setLayoutO (Box), 386 355 setLayout() (JTooffiar), 222 showlnputDialogO (JOptionPane), 299, 300, 302 setLookAndFeel() (UIManager), 748,749 showlntema!ConfirmDialog() (JOptionPane), 301 setMajorTickSpacingO (JSlider), 441 showlnternallnputDialog() (JOptionPane), 302 setMaximum() showlntema!MessageDialogO (JOptionPane), 301 JScrollBar, 433 showlntema!OptionDialog() (JOptionPane), 303 }Slider, 439 showMessageDialog() (JOptionPane), 301 setMaximurnRowCount() (JComboBox), 501 showOpenDialog() (JColorChooser), 353 setMinimum() showOptionDialog() (JOptionPane), 303 JScrollBar, 433 showPopup() (JComboBox), 501 }Slider, 439 showSaveDialogO (JColorChooser), 353 setMinimumSize() (JComponent), 395 SimpleAttributeSet setMinorTickSpacing() (JS!ider), 441 about, 589, 605 setMnemonic() (Abstract Button), 115 constructors, 606 setModel() (JTree), 622 creating. 606 setOpaqueO (JTextComponent), 526 examples,606-609 setOrientationO properties, 606 ]Separator, 201 SingleSelectionModel, 172,177-178, 194,400,405 JTooffiar, 226 SINGLE_TREE_SELECTION, 679 setPaintLabelsO (]Slider), 443 SizeRequirements, 381 setPaintTicksO (]Slider), 440 SizingSamples, 478-479 setPaintTrackO (]Slider), 445 slider. See thumb setParentO (MutableTreeNode), 663, 664 SliderUI, 436 setPopupVisible() (JMenu), 177 SoftBeveffiorder, 241 setPosition() (JLayeredPane), 260 spacebar, selection by pressing, 53 setPreviewPanel() (JColorChooser), 335,347 start() (Timer), 67 setProgress() (ProgressMonitor), 317,318 state changes setRequestFocusEnabled() (JComponent), 55 MVCand, 76 setResizable() (]Frame), 769 observing, 22 setSelected() (ButtonGroup), 130-131 signifying, 33 setSelectedlcon() UndoableEdit, 791-792,793 }CheckBox, 140 StateEdit, 783, 802-806 JRadioButton, 148 objects, 783, 803 setSelectedlndex() (JComboBox), 502-503 StateEditable, 784, 802-806 setSelectedlnterval() (JList), 490 objects, 803 setSelectedltem() (JComboBox), 502 Steel theme, 779 setSelectedValue() (JList), 490 stop() (Timer), 67 setSnapToTicks() (]Slider), 442 stopCellEditingO (CellEditor), 655 setSourceElements() (Dua!ListBox), 492 storeStateO (StateEditable), 802 setString() (JProgressBar), 450 StringContent, 604 setStringPainted() (JProgressBar), 450 struts, 388, 390 setText() (JMenultem), 594 Style, 582, 602, 615 setToolTipText() (]Component), 93, 99 Style objects, 602

856 Index

StyleConstants, 589, 602,610-611 Swing components (continued) StyleContext, 602, 615 StyleContext.NamedStyle, 602, 615 button,llO StyleContext.SmallAttributeSet, 602, 610 chapters where discussed, 18-19 StyledDocument clipboard, 538--539 about, 522, 601 complete list of, 767-768 definition,602-604 configurable settings, 83 and JEditorPane, 576 container delegate for, 255 for JTextPane, 585 core, 79-126 UML relationship diagram, 603 creating new ones with }Panel, 124 use with JTextField, 532 customized focus management, 60-61 See also DefaultStyledDocument data model interfaces and StyledEditorKit, 596 implementations, 76 subclass relationships, notation for, 4 default borders, 229 settings, 125 Sun Microsystems Web sites, 6, 16, 17 default opaque superclass relationship, notation for, 4 example of simple, 124-125 setting property values of, 64 super.insertStringO. 545 getting or super.paintComponent(), 81 heavyweight, 768 super.remove(), 545 HTML viewer, 128 Swatches panel, 336, 337, 339 managing layering of, 259 170 Swing menu element, approach, 10 mixing with AWT components, 195 event-handling capabilities, 39-53 naming convention for, 8--9 event package, 25 new,10-14 and, 81 event-related class hierarchy, 41 optimized drawing focus management, 53-64 properties defined by, 19 99 Java 2 demonstration program, 17-18 registering directly, 55 libraries, size of, 1 requestFocus() and, and, 55 missing constructor, 133 requestFocusEnabled new capabilities, 172 reserving extra space around, 236 53-54 origins of, 7 setting the focus, release 1.0.3, 2, 16 sharing a common property setting among, release 1.1 31 multiple, 25 about, 2 sharing listeners across bugs, 58, 187 thread safety, 64 changing frame icons, 279 toggleable, 127-163 installing, 16 transparent, 82 unsupported functions, 196 UI delegates, 73, 752 drawing components unsupported items, 185 Swing container objects, within, 81 unsupported property, 174 Swing containers release 1.1.1 150 capabilities, 2 for JRadioButton components, }Frame close operation, 264 JTooffiar, 220 new methods, 51 menu item, 185 for popup-menu components, 194 release 1.2.1 new features, 96 Root Pane, 255-288 technical support Web sites, 5-6 usingJPanelas, 124 thread safety, 40 working with, 383--423 See also classes Swinglayoutmanagers,369-382 See also LookAndFeel Swing text package info, 616 See also MVC (Model-View-Controller) SwingConstants, 102 Swing component properties. See properties swing.defaultlaf system property, 751 Swing components swing. properties file, 751, 781 adding to a frame, 26 SwingPropertyChangeSupport, 33 adding to a menu, 216 SwingSet, 17-18 asking about size of, 233 associating Action with, 42 AWT components replaced by, 9 AWTWindow objects replaced by, 10 bounded range, 425-458

857 Index

SwingUtilities TabStop objects, 612 methods,450,452, 749 technical support, 5-0 using for mouse button identification, test driver, 124 29-30 TestApplet, 274 using for thread safety, 40, 65-66 text SwingUtilities.invokeLater(), 751 creating styled, 601--015 symbols used in this book, 4 displaying stylized, 589 SystemColor, 339-340 painting selected, 550, 551 SystemColorChooserPanel, 337, 338, 340-345 See also content See also HTML See also PlainDocument Text components T basic, 521-523 class hierarchy, 522 Tab and Shift-Tab keys, 54, 58, 60, 61 data model, 540 tab stops eventhandling,558 in JTextArea, 571 listeners for, 548-558 for a JTextPane, 612 loading and saving content, 532-536 tabbed panes, 400 loading and saving example, 534 Table components, 692 undo with, 784, 786-789 table header icons, 731 text components TableCellEditor, 690, 691,735-736,739, 742 Action objects and, 42 TableCellRendered, 691 text field, restricting input into, 544 TableCellRenderer, 690, 702-705, 730, 736-737 text labels TableColumn defming apart from a component, 188 about,690,728-729 htrnl tag support for, 94 constructors, 729 mnemonic key, 114 example, 691 TextAction properties, 729-730 abou~40,523,537,590-591 TableColurnnModel, 690, 691, 699, 724-732 example,592-594,595,599,600--001 TableColumnModeiEvent, 726 finding actions, 596--001 TableColurnnModelListener with JTable events, listing actions, 590-594 726-728 name constants, 597-598 TableExarnple, 722 objects, 72, 594, 598, 600 TableHeaderSorter, 723-724 using actions, 594-596 TableMap, 717,722-723 TextArea, 570 TableModel, 690,691,707-724 TextEvent, 523 TableModelEvent, 715 TextField, 521 TableModelListener TextListener, 558 with }Table events, 714-715 TextPaneSarnple,585-587 list management, 707 TextSJider, 457-458 tables, 689-743 Textm, 73 displaying information in, 11 TextUtilities, 539 TableSorter, 717-722 TheGridBagConstraints, 497 tabs themes, 777-781 changing default ordering of, 64 thread safety, 40, 64-66, 319 controlling position intervals of, 573 threads selecting in back row, 406 starting, 451 specifying container location for, 401, 402 updating, 452 too wide for the display, 406 thumb TabSarnple,405-406,613-614 about, 428 TabStop draggable, 436 about, 612 icon, 446 alignment, 613 multiple time use of, 310 constants, 612, 613, 615 positions and tracks, 445 constructor, 612 snapping into position, 442 creating, 612 tick marks within a }Slider, 440-442 properties, 612, 615 TickSJiders, 441-442

858 Index

Timer, 40, 66-68 TreeExpansionEvent, 685 TitledBorder TreeExpansionUstener, 685 about, 246 Tree.hash, 631 constants, 2480 TreeModel, 620, 662, 677-679 constructors, 246-248 TreeModelEvent, 679 look and feel, 250--251 TreeModelUstener, 679 methods, 246-248 TreeModellistener objects, 677, 678 multiple titles on single border, 250 TreeNode,648,662-663,668-670 properties, 248-250 See also MutableTreeNode samples, 246 Tree Path title justifications, 249 about, 620, 670, 684 UIResource elements, 250-251 array of elements, 628 toArrayO (DefaultUstModel), 469 constructors, 684 toggle buttons, 127-163 example, 685 ToggleButtonModel, 127-128, 129, 132 methods, 684 ToggleButtonUI, 132, 220 objects, 656, 681, 684 Tooffiar.framelmagelcon, 769 properties, 684 toolbars, 165, 220--227 trees, 619-687 draggable, 12 TreeSelectionEvent, 682 outside main window, 769, 770 TreeSelectionUstener, 682-684 TooffiarSample,225-226, 770--771 TreeSelectionModel, 620, 679 TooffiarUI, 769 TreeSelectionSample, 682-684 ToolTipManager TreeTester, 671, 677 about, 97 TreeTips, 641 }Table, 705 TreeUI,628 and JTree, 639, 641 cache bug, 634 methods,94,97,98 TreeWillExpandUstener, 686-687 properties, 97-99 troubleshooting tooltips version differences and, 2 disabling, 98 Web sites for information on, 5-6 displaying positional text, 95-96 See also errors JTabbedPane, 403 }Table, 705 JTableHeader, 733-734 text in custom colors, 95 u text support for, 46, 256 ToolTipTreeCel!Renderer, 640,641 UI Delegates ToolTipUI delegate, 96 about, 73 toStringO adding, 776-777 JComboBox, 510 automatic registration, 755 JUst, 475,477 creating new, 767-772 Object, 624, 681 creation sequence diagram, 772 TreeNode, 633 functions, 745 Transferable, 672 for Swing components, 752 Transferable clipboard objects, 536 UIDefaults, 83-84, 745,746,753-758,760 TransferableTreeN ode, 672-674 UIDefaults.ActiveValue, 760-764 transferFocusQ (Component), 53, 54,55 UIDefaults.ActiveValue objects, 745 translateD (Graphics), 232 UIDefaults.LazyValue objects, 745 transparent borders, 233 UIManager transparent components, 404 about, 745,746,752-753 TraverseTree,669 getDefaultsQ, 84 tree traversal example, 669, 684 methods,83,84, 747-748,753 TreeArraySample,624-625,670 properties, 753-754,808-822 TreeCel!Editor UIManager.getQ, 763, 767 about, 619, 642, 643 UIManager.LookAndFeellnfo, 745,754 methods,653,657 UIManager.LookAndFeellnfo objects, 754 using, 682 UIManager.putQ, 763, 771 TreeCel!Renderer, 99,619, 632-641

859 Index

UIResource undo() about,83, 745,758-759 AbstractUndoableEdit, 801 components, 759 CompoundEdit, 793 properties,808-822 UndoManager, 784,791,792,796 Desktoplcon, 283 Undo and Redo presentation names, 793 FileView, 367 undoable objects, 802 JButton, 122 Undoable or Redoable state, 795 ]CheckBox, 147 Undoable program example, 798-202 JCheckBoxMenultem, 207 Undoable state, 792, 793 JColorChooser, 348 UndoableDrawEdit, 799,801-802 JComboBox, 515 UndoableDrawingPanel, 798, 799-801, 802, JDesktopPane, 285 804-806 JEditorPane, 582 UndoableEdit JFileChooser, 366 about, 783, 789 JinternaJFrame, 281 default implementation, 793 JLabel, 104 definition and methods, 791-792 JList, 492 exposiing Jist for, 796 JMenu, 192 implementation, 799, 801, 802, 803 JMenuBar, 175 Invoker, 790 JMenultem, 185 objects, 796, 799, 804 JOptionPane, 314 state chart, 792 ]Panel, 126 UndoableEditEvent, 784, 796 JPasswordField, 569 undoableEditHappened() JPopupMenu, 200 (UndoableEditSupport), 797 JProgressBar, 456 UndoableEditListener, 784, 795, 796 JRadioButton, 162 objects, 799, 803 JRadioButtonMenultem, 212 UndoableEditSupport, 796-798, 803 JScrollBar, 435 about, 784 JScrollPane, 416 in an example, 799 ]Separator, 194 UndoDrawing, 798-799, 804-806 ]Slider, 445 UndoManage~784,794-796,798,804 JSplitPane, 399-400 UndoManagerHelper, 786-788 JTabbedPane, 407 UndoSample, 786788-789 }Table, 706 Unicode, 543 JTableHeader, 734 Unified Modeling Language. See UML diagrams JTextArea,574 uninstaJIChooserPanel() JTextField, 566 (AbstractColorChooserPanel), 339 JTextPane,584-585 unregisterComponent() (ToolTipManager), 98 JToggleButton, 138-139 update() with Swing components, 80 JToolBar, 224 updateChooser() (AbstractColorChooserPanel), JToolTip, 96 339,340 JTree,629-630,631 updateComponentTreeUI() TextField.selectionBackground, 551 SwingUtilities, 749 TitledBorder, 250-251 UIManager, 753 UIManager Methods for getting, 85' updateUI() using Color objects as, 759 Border, 229 Viewport, 423 JColorChooser, 335 UML diagrams, how to read, 4-5 UIManager, 753 Undo, 783, 786 URL objects, 576 UML relationship diagram, 785 UseActions, 600-601 using with non-Swing text components, delegates. See UI Delegates 789-806 user interfaces, 65 user objects, 662, 664, 666 non-String, 671

860 Index users w exiting a frame, 27 getting input from, 11, 73 for range of values, 436 Web sites selecting table columns and rows, 724 for Japanese fonts, 689 via pop-up windows, 289 Sun Microsystems, 6, 16, 17 offering choices of colors to, 736-739 Swing Connection, 616 presenting output to, 446 Swing PLAF Differences list, 808 use of keystroke to activate event, 51 Tab Splitter, 400 viewing of progress of activity, 11 for technical support, 5-6 who customize screens, 91 WindowConstants, 262, 264 See also event handling Wmdowlistener with }Frame events, 265, 266 See also event listeners windows "Uses" stereotype, 5 with labels and JFileChooser, 351-352, 353 pop-up text within, 98 Wmdows MDI, 13, 255, 275, 276 WindowsDesktopManager, 287 v WindowsLookAndFeel, 74 7 WrappedPlainView, 73 write() (JTextComponent), 527, 532,533-534 valueForPathChanged() (TreeModel), 677 VariableHeightLayoutCache, 681 Vector for creating nodes for trees, 670 y NamedVector, 624 objects, 692 storing data in form of, 462 YAxisAlignX, 373 vertical toolbars, 221 VerticalMenuBar, 176, 177 VERTICAL_SCROLLBAR, 410, 414 vetoableChange() (VetoableChangelistener), 91 VetoableChangelistener with }Component events, 91 VetoableChangeSupport, 796 view changes to the, 73 class hierarchy diagram, 617 getting a specific, 361 }Table, 694 moving the, 415 position of, 418 rendered by Swing text delegate, 589 scrolling the, 419-422 Swing component, 75 Swing text component, 540 UI delegate as, 745 working with, 616 ViewFactory, 616 VIEWPORT, 414, 415--416 Viewport, 423 ViewportLayout, 382, 416-417 viewToModel() (JTextComponent), 527 VK_ • key constants, 51, 115, 180

861 Apress· License Agreement (Single-User Products)

THIS IS A LEGAL AGREEMENT BE1WEENYOU, THE END USER, AND APRESS. BY OPENING THE SEALED DISK PACKAGE, YOU ARE AGREEING TO BE BOUND BY THE TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO THE TERMS OF THIS AGREEMENT, PROMPILYRETURN THE UNOPENED DISK PACKAGE AND THE ACCOMPANYING ITEMS ONCLUDING WRITTEN MATERIAL') AND BINDERS AND OTHER CONTAINERS) TO THE PLACE YOU OBTAINED THEM FOR A FUll REFUND.

APRESS SOFIWARE UCENSE

1. GRANT OF UCENSE. APress grants you the right to use one copy of this enclosedAPress software program (the "SOFIWARE") on a single terminal connected to a single computer (i.e., with a single CPU). You may not network the SOFIWARE or otherwise use it on more than one computer or computer terminal at the same time.

2. COPYRIGHT. The SOFIWARE copyright is owned by APress or its suppliers and is protected by United States copyright laws and international treaty provisions. Therefore, you must treat the SOFIWARE like any other copyrighted material (e.g., a book or musical recording) except that you may either (a) make one copy of the SOFIWARE solely for backup or archival purposes, or (b) transfer the SOFIWARE to a single hard disk, provided you keep the original solely for backup or archival purposes. You may not copy the written material accompanying the SOFIWARE.

3. OTHER RESTRICTIONS. You may not rent or lease the SOFIWARE, but you may transfer the SOFTWARE and accompanying written materials on a permanent basis provided you retain no copies and the recipient agrees to the terms of this Agreement. You may not reverse engineer, decompile, or disassemble the SOFIWARE. H SOFIWARE is an update, any transfer must include the update and all prior versions.

4. DUAL MEDIA SOFIWARE. H the SOFIWARE package contains both 3.5 • and 5.25" disks, then you may use only the disks appropriate for your single-user computer. You may not use the other disks on another computer or loan, rent, lease, or transfer them to another user except as part of the permanent transfer (as provided above) of all SOFIWARE and written materials.

UMITED WARRANTY

UMITED WARRANTY. APress warrants that the SOFIWARE will perform substantially in accordance with the accompanying written material for a period of 90 days from the receipt. Any implied warranties on the SOFIWARE are limited to 90 days. Some states do not allow limitations on duration of an implied warranty. so the above limitation may not apply to you.

CUTOMER REMEDIES. APress's entire liability and your exclusive remedy shall be, at APress's option, either (a) return of the price paid or (b) repair or replacement of the SOFIWARE that does not meetAPress's Limited Warranty and which is returned to APress with a copy of your receipt. This limited warranty is void if failure of the SOFIWARE has resulted from accident, abuse, or misapplication. Any replacement SOFIWARE will be warranted for the remainder of the original warranty period or 30 days, whichever is longer. These remedies are not available outside of the United States of America.

NO OTHER WARRANTIES. APress disclaims all other warranties, either express or implied, including but not limited to implied warranties of merchantability and fitness for a particular purpose, with respect to the SOFIWARE and the accompanying written materials. This limited warranty gives you specific rights. You may have others, which vary from state to state.

NO UAB!UTIES FOR CONSEQUENTIAL DAMAGES. In no event shall APress or its suppliers be liable for any damages whatso• ever (including, without limitation, damages from los's of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use or inability to use this APress product, even ifAPress has been advised of the possi• bility of such damages. Because some states do not allow the exclusion or limitation of liability for consequential or incidental damages, the above limitation may not apply to you.

U.S. GOVERNMENT RESTRICTED RIGHTS

The SOFIWARE and documentation are provided with RESTRICTED RIGHTS. Use, duplication, or disclosure by the Government is subject to restriction as set forth in subparagraph (c)(l)(ii) of The Rights in Technical Data and Computer Software clause at 52.227-7013. Contractor/manufacturer isAPress, 6400 Hollis Street, Suite 9, Emeryville, CA 94608.

This Agreement is governed by the laws of the State of California.

Should you have any questions concerning this Agreement, or if you wish to contact APress for any reason, please write to APress, 6400 Hollis Street, Suite 9, Emeryville, CA 94608.