Chapter 23. The javax.swing Package

This large package contains the most important classes and interfaces
of Swing. Swing is a core part of Java 1.2 and is also available as a
standard extension to Java 1.1. The GUI
component classes are at the heart of Swing.
These classes have names that begin with the
letter J.
Figure 23-1 shows the hierarchy of
Swing components in javax.swing. Note that
this diagram does not show the fact that all the Swing components
implement javax.accessibility.Accessible;
see the individual
class synopses for this information.

Figure 23-1. Components of the javax.swing package

Most Swing components rely on a model object to hold
their state information. Various interfaces define the methods that
these state objects must implement, and various abstract and concrete
classes implement these interfaces. These model interfaces and
classes are recognizable by the word "Model" in their names.
Figure 23-2 shows the model objects and
layout managers in javax.swing.

Classes
with the word "Manager" in their names typically manage some important
part of the Swing user-interface or application environment. Other
important classes and interfaces defined by this package include:
Action, Icon,
KeyStroke, Timer, and
SwingUtilities.
Figure 23-3 shows the rest of the classes
and interfaces in javax.swing.

All Swing components are accessible, which means that they implement the
javax.accessiblity.Accessible interface and define getAccessibleContext() methods. This method returns a javax.accessibility.AccessibleContext object that provides support to accessibility tools, such as screen readers for the vision impaired. Each accessible component has its own specific subclass of AccessibleContext, which is typically defined as a protected inner class of the component.
These AccessibleContext inner classes have been omitted from this chapter and from
Figure 23-1 because they contain little useful information and they detract from other, more important classes. Practically everything you need to know about an AccessibleContext subclass can be found in the single-line inner class synopsis that appears in the containing class, the accessible flag of the containing class, and in Chapter 22, "The javax.accessibility Package".

Figure 23-2. Models and layout managers of the java.swing package

Figure 23-3. Other classes and interfaces of the javax.swing package

AbstractAction

Java 1.2

javax.swing

cloneable serializable

This class implements all the methods of the
Action interface except for the crucial
actionPerformed() method that provides the
substance of the action. Subclassing
AbstractAction is one of the easiest ways to define
Action objects for your application. Note the one-
and two-argument constructors. These constructors automatically
define name and icon attributes for the action and are simpler
than using putValue().

This class serves as the superclass for Swing components with
buttonlike behavior. Because it is a general-purpose class, it
defines a large number of properties. Like Swing labels, Swing buttons
can display text and/or an icon, and several properties specify the
relative positioning of the text and icon. (See
JLabel for details on these positioning
properties.) Swing buttons can display different icons when in
different states. In addition to the default icon,
AbstractButton has properties that specify icons to
be displayed when the button is pressed, selected, disabled, disabled
and selected, rolled over, and rolled over and selected. If the
rolloverIcon property is specified and if the
rolloverEnabled property is
true, the rolloverIcon is
displayed when the mouse is over the button.

By default, an AbstractButton displays a single
line of text in a single font. However, as of Swing 1.1.1 and Java
1.2.2, if the text property begins with
"<html>", the button text is formatted as HTML and may
contain multiple fonts and multiple lines.

A Swing button may be enabled and disabled with
setEnabled(). Disabled buttons are typically
displayed with grayed-out graphics, although some other disabled icon
can also be specified. A mnemonic can be specified with
setMnemonic(). This causes the mnemonic character
to be underlined in the button's text and allows the button to be
operated via the keyboard.

Swing buttons generate three types of events. A
java.awt.event.ActionEvent is generated when any
button is pushed. A java.awt.event.ItemEvent is
generated when a toggle-type button is selected or deselected. And a
javax.swing.event.ChangeEvent is generated when
the button's internal state changes--for example, when the mouse
pointer enters the button or when the user arms the button by
pressing the mouse button.

This protected inner class is a simple
Serializable implementation of
javax.swing.
event.ChangeListener that
AbstractButton uses internally to receive change
notifications from its ButtonModel.
Application-level code never needs to use this class.

This abstract class provides a partial implementation of the
ListModel interface. Subclassing
AbstractListModel is usually easier than
implementing ListModel from scratch. Note,
however, that the DefaultListModel class is a
usually an adequate ListModel implementation, so
you shouldn't need to subclass AbstractListModel
very often. Furthermore,
the JList component provides convenience methods
that often make it unnecessary to work with any kind of
ListModel at all.

An action is a single piece of application functionality, such
as saving a file or printing a document. The actions performed by an
application may be made available to the user in several different
ways: in a pulldown or popup menu, in a toolbar, and from a keyboard
binding, for example.

The Action interface extends
java.awt.event.ActionListener and adds the ability
to enable or disable the action. If an editor contains an empty
document, its print action probably should not be enabled, for
example. setEnabled() specifies whether the action
is enabled. When an action is enabled or disabled, this change
is broadcast by a java.beans.PropertyChangeEvent.

The Action interface also defines methods that
associate attributes with an action. The putValue()
method maps an arbitrary attribute name to an arbitrary attribute
value. The getValue() method queries an attribute
value. The constants defined by the Action
interface specify predefined names for commonly used attributes.
NAME and SMALL_ICON are the most
commonly used.
Finally, the actionPerformed() method, inherited
from ActionListener, is responsible for
performing the action.

JMenu, JPopupMenu, and
JToolBar define methods that allow
Action objects to be added to them. These methods
query the action for its name and an icon that represents the
action and use this information to present the action to the user.
If the action is enabled, the component allows the user to invoke it.
The JTextComponent and Keymap
classes from the javax.swing.text package
additionally provide techniques for mapping keystrokes to
Action objects.

AbstractAction provides a useful starting point for
defining your own Action classes.

The static methods of this class return various types of
Border
objects. These methods may return previously created shared objects,
making their use more memory-efficient than creating unshared
Border
objects with the new operator. See the various
classes of the javax.swing.border package for
more information on the types of borders supported by Swing.

This interface defines the data model used by the
JScrollBar, JSlider, and
JProgressBar components. The model is defined by
four integer properties that obey the following relationship:

minimum <= value <= value+extent <= maximum

The value property specifies the value currently displayed
by the component. It must be between the values specified
by the minimum and
maximum properties. The
extent property
specifies the amount of data displayed. For
JScrollBar components, this property specifies the
size of the scrollbar thumb, or knob.
Note the convenience method setRangeProperties()
that sets all properties of the model at once.

When any value changes, interested listeners are notified with
a javax.swing.event.ChangeEvent. One additional
property defined by this interface is
valueIsAdjusting. If this
property is true, it means that a series of rapid
property changes (such as those caused when the user drags the
scrollbar) is in progress. This property is
false for the last change in the series, so
listeners can therefore choose to ignore transient changes that have
this property set to true.

DefaultBoundedRangeModel is an implementation of
this interface appropriate for most uses.

This class is a container that uses the
BoxLayout layout manager to arrange its children in
a row or a column. Pass one of the constants
BoxLayout.X_AXIS or
BoxLayout.Y_AXIS to the constructor to create a
horizontal or vertical box or use the static methods
createHorizontalBox() and
createVerticalBox(). A horizontal box attempts to
lay out its children from left to right, one next to the other, at
their preferred widths and tries to make each child as tall as the
tallest child. A vertical box does the opposite: it lays out its
children from top to bottom, trying both to maintain the preferred height
of each child and to make all children as wide as the widest
child.

The arrangement of children in a Box is often
improved with the use of
struts and glue: invisible components that exist only to
improve the appearance of a layout. A horizontal strut has 0
height and has a specified value as its minimum, preferred, and
maximum width. A vertical strut has 0 width and a fixed height.
Struts are useful for inserting fixed amounts of space between
components in a Box. Use
createHorizontalStrut() and
createVerticalStrut() to create struts.

Glue is a component with a preferred width or height of 0 but
with an infinite maximum width or height. Glue is used to specify
where extra space in a layout should go. For example, if you have
three fixed-sized JButton components in a row that
is wider than the sum of the button widths, placing glue between
them forces them to be evenly spaced. Use
createHorizontalGlue() and
createVerticalGlue() to create glue components.

This class implements the invisible component used to create
struts and glue for use with the Box container. It
allows you to create an invisible component with any specified
minimum, preferred, and maximum sizes.

This class enforces mutual exclusion (radio behavior) for a
group of toggle buttons. Once buttons are added to a
ButtonGroup with the add()
method, mutual exclusion is automatic, and no further action is
necessary.

public class ButtonGroup implements Serializable {

//

Public Constructors

public ButtonGroup ();

//

Property Accessor Methods (by property name)

public java.util.Enumeration getElements ();

public ButtonModel getSelection ();

default:null

//

Public Instance Methods

public void add (AbstractButton b);

public boolean isSelected (ButtonModel m);

public void remove (AbstractButton b);

public void setSelected (ButtonModel m, boolean b);

//

Protected Instance Fields

protected java.util.Vector buttons ;

}

Hierarchy: Object-->ButtonGroup(Serializable)

Passed To: ButtonModel.setGroup(), DefaultButtonModel.setGroup()

Type Of: DefaultButtonModel.group

ButtonModel

Java 1.2

javax.swing

model

This interface defines the model for Swing buttons. This model
consists of five boolean
properties that specify the current selection
state of the button and three other properties that specify an
optional mnemonic, ButtonGroup, and action command
(a string passed with a java.awt.event.ActionEvent)
for the button.

This interface defines general methods that must be implemented
by any cell editor object. isCellEditable() should
return true if the cell is editable and if the
specified event is an appropriate event to trigger an edit. (For
example, some programs might require a double-click to edit a cell.)
shouldSelectCell() should return
true if the given event should cause the cell to
become selected or false otherwise. However, this
is only a minor secondary purpose of the method. Despite its name,
the primary purpose of shouldSelectCell() is to
cause the cell editor to begin editing the cell. The editor can use
the specified event to set the initial state (e.g., cursor position) of
the editor.

getCellEditorValue() returns the value being
edited. cancelCellEditing() cancels an edit.
stopCellEditing() instructs the editor to stop
editing and accept a partially edited value. An editor may return
false if it cannot accept the current value
(because the partial value is not valid, for example). If the editor
stops or cancels editing itself, it sends a
javax.swing.event.ChangeEvent to any registered
javax.swing.event.CellEditorListener objects.

javax.swing.table.TableCellEditor and
javax.swing.tree.TreeCellEditor are table- and
tree-specific cell editor interfaces;
DefaultCellEditor is an implementation of both
those interfaces.

This class is used by Swing components that rely on cell renderer
interfaces, such as ListCellRenderer,
javax.swing.table.TableCellRenderer, and
javax.swing.tree.TreeCellRenderer. The methods
of this class are used to paint a single cell renderer component at
various specified locations within a container.

This interface defines the methods that must be implemented by an
object that wishes to serve as the editor object for a
JComboBox
component. It is typically implemented as part of a pluggable
look-and-feel and is not normally used by application programmers.

This interface defines the basic model used by the
JComboBox component. The
JComboBox allows the user
to select a value from a list or type a value directly. Therefore,
ComboBoxModel extends ListModel
to add support for a selected item, in addition to the list of items
that ListModel already supports.
See also MutableComboBoxModel and
DefaultComboBoxModel.

This subclass of java.awt.Graphics reimplements
most of the methods of its superclass to facilitate debugging of
drawing operations. Instances of this class are rarely used directly;
programs can enable graphics debugging by calling
setDebugGraphicsOptions() on any Swing component.

This class implements both the
javax.swing.table.TableCellEditor and the
javax.swing.tree.TreeCellEditor interfaces. It
is the default editor class used by JTable.
Instances of this class can be created to
use a specified JTextField,
JCheckBox, or JComboBox as the
editor component.

This DefaultCellEditor class can use a
JTextField, JComboBox, or
JCheckBox as the cell editor component. This
protected inner class is used internally by
DefaultCellEditor to encapsulate the differences
between these three editor components.
Application-level code never needs to use this class.

This MutableComboBoxModel implementation is the
default model object used by the JComboBox
component. In addition to the methods of the
MutableComboBoxModel,
ComboBoxModel, and ListModel
interfaces, DefaultComboBoxModel also implements
methods to remove all elements from the list and to find a
specified element in the list.

This class is a simple default implementation of the
DesktopManager interface. It can be used as a
starting point for pluggable look-and-feel
DesktopManager implementations. It is also used to
manage JInternalFrame components that are not
within a JDesktopPane. Appliations typically do not need to use this class.

This class is the default ListCellRenderer used by
the JList component to render the items of the
list. This class extends JLabel and uses
JLabel features to render list items. Since
JList uses this class by default, you should not
have to instantiate or use it directly.

This class is a trivial wrapper around
DefaultListCellRenderer. It implements the empty
javax.swing.plaf.UIResource marker interface in
order to distinguish cell renderers supplied by a look-and-feel from
cell renderers supplied by the user.
Like all classes that implement UIResource, this
class is used by implementors of custom look-and-feels. Applications
do not need to use this class.

This class is a ListModel implementation that is based on
AbstractListModel, with the addition of
java.util.Vector methods for modifying the values
contained in the list. This class is suitable for most uses of the
JList component, but you may on occasion want to
implement a custom ListModel, probably by
subclassing AbstractListModel.

This class is the default implementation of the
ListSelectionModel interface. It is used by
JList and JTable components.
Typical applications do not need to explicitly use this class or
the ListSelectionModel interface.

This interface defines the methods that must be defined by a pluggable
look-and-feel to manage JInternalFrame windows
within a JDesktopPane container. Application
programmers do not need to use this class.

This abstract class defines three instance methods that must be
implemented by an object that wants to manage keyboard focus for an
application. It also defines static methods that manipulate the
installed focus manager. Applications that mix AWT components with
Swing components should call
disableSwingFocusManager() to disable Swing's focus
management and rely on the AWT focus manager. Call
setCurrentManager() to replace the current focus
manager with a custom manager of your own.

This class is a java.awt.image.ImageFilter that
converts a color image to a grayscale image, suitable for use as an icon that
represents a disabled action or an unavailable option. In addition to the
usual ImageFilter methods,
GrayFilter provides the static
createDisabledImage() method, which is all that most
applications ever need to use. The
AbstractButton and JLabel
classes use GrayFilter to automatically create a
grayscale version of an image, if no disabled image is explicitly provided.

This interface defines the Swing notion of an icon: an object that
knows how to draw a graphic of a fixed width and height at a fixed
location. Icons are most commonly implemented with images; see
ImageIcon.

This class is an implementation of the Icon
interface that uses an Image to draw the icon. The
various constructors allow the image to be specified as an
Image object, as a URL, as a file name, or as an
array of binary data. Every ImageIcon can have a
short textual description that may be used for accessibility (e.g.,
to describe the icon to a blind user).

This class is the Swing version of its superclass,
java.applet.Applet. It creates a
JRootPane as its sole child, and, like
JFrame, JDialog, and similar
classes, it implements RootPaneContainer. Calling
add() or setLayout() on a
JApplet raises an exception. Instead, call
getContentPane() to obtain a reference to an
internal container on which you can call add() and
setLayout(). The default layout manager for
this content pane is a BorderLayout. Because
JApplet is a RootPaneContainer,
it can display a Swing menubar. Use setJMenuBar()
and getJMenuBar().

This class implements a push button. The constructors allow a textual
label and/or an icon to be specified for the button.
isDefaultButton() checks to see if the button is
the default button registered with the
setDefaultButton() method of
JRootPane. A
JButton generates
a java.awt.event.ActionEvent when clicked. Most of
the interesting properties and methods of JButton
are implemented by AbstractButton.
The default JButton model is
DefaultButtonModel.

This class implements a check button: a toggle button with
default graphics that indicate that the button does not
have mutually exclusive behavior. Because
JCheckBox supplies its own default and selected
icons, you typically do not use the constructors that take
Icon arguments. The initial selection state of a
JCheckBox can be specified in the call to the
constructor. The state can also be set
with setSelected() and
queried with isSelected(). Use
JRadioButton and ButtonGroup
instead of JCheckBox if you want to display a set
of mutually exclusive choices.
The default JCheckBox model is
JToggleButton.ToggleButtonModel.
Note that java.awt.Checkbox is spelled with a
lowercase b, while JCheckBox has an uppercase B.

This class implements a check button that appears within a pulldown or
popup menu. Its use is similar to that of
JCheckBox. Use isSelected() to
query the selection state of the menu
item and setSelected() to select or deselect
the item. For
menu items with mutually-exclusive selection behavior, use
JRadioButtonMenuItem instead.
The default JCheckBoxMenuItem model is
JToggleButton.ToggleButtonModel.

This component allows the user to select a color. The easiest way to
use it is to call the static showDialog() method,
specifying a parent Component for the dialog, a
title, and an initial default color. The method
creates a JColorChooser in a modal
JDialog and blocks until the user dismisses the
dialog. If the user dismisses the dialog with the OK button, the method returns the selected color. If
the user dismisses the dialog with the Cancel button, or in any other way,
showDialog() returns null.

If you need more control over the color selection dialog, you can call
createDialog(). This static method creates a
JDialog that contains the
JColorChooser component you specify. It allows you
to specify java.awt.event.ActionListener objects to
respond to the OK and Cancel buttons. It does not automatically
display the dialog for you, nor does it wait for the user to make a
selection.

You can also create and manipulate a JColorChooser
on your own, placing it in any dialog or other container. You can
register a java.beans.PropertyChangeListener object
(with the inherited addPropertyChangeListener()
method) to receive notification when the color
property changes.

JColorChooser is highly customizable. You can
specify how colors are selected by specifying a custom
subclass of
javax.swing.colorchooser.AbstractColorChooserPanel
to addChooserPanel() or
setChooserPanels().
And you can customize the way that colors are previewed by
specifying an appropriate component to
setPreviewPanel().
The default JColorChooser model is a
javax.swing.colorchooser.DefaultColorSelectionModel.

This class implements a combo box: a combination of a popup
list of selectable items and an item editor that
displays the selected value and, optionally, allows the user to
enter an item that does not appear on the list. The editor is
usually a text field, but a JComboBox can be
configured to use another component as its
ComboBoxEditor.

Typically, you create a JComboBox by passing
a Vector or array of objects to a constructor.
Alternatively, you
can create an empty JComboBox and add items to it
with addItem(). You can set and query the
selection with setSelectedItem(),
setSelectedIndex(),
getSelectedItem(), and
getSelectedIndex(). The
JComboBox generates a
java.awt.event.ActionEvent when the selection
changes.
The default JComboBox model is a private
implementation of the ComboBoxModel interface.
If you want to implement keyboard shortcuts for a
JComboBox, implement the
JComboBox.KeySelectionManager interface and pass
an instance to the setKeySelectionManager()
method.

This interface defines the method that must be implemented to
bind characters to items in a JComboBox. Given a
character, selectionForKey() should return the
index of the item that should be selected or -1 if the character does
not correspond to an item in the list.

JComponent is the root of the Swing component
hierarchy. It inherits the properties and methods of
java.awt.Component and
java.awt.Container, including such commonly used
properties as foreground,
background, font,
cursor, enabled, and
visible.

In addition to these inherited properties, JComponent
defines a number of new properties that are commonly used. The
border property specifies a
Border object that displays a border (or a blank
space) around the component. doubleBuffered
specifies whether the JComponent should
automatically use double-buffering to reduce flickering during
redraws. opaque specifies whether the component
draws its background or lets its parent' background show through.
toolTipText specifies the text to appear in a
tooltip when the mouse pointer lingers over the component.

In addition to the standard get/set property accessor methods,
JComponent also defines
getClientProperty() and
putClientProperty(). In effect, every
JComponent maintains a hashtable that maps arbitrary
property names to values. You can use this to associate arbitrary
data with any Swing component. It is also occasionally used to
specify properties that are specific to certain look-and-feels.

This class is used to display Swing dialog boxes. Every
JDialog component has an automatically created
JRootPane as its single child. Components must not
be added directly to the JDialog component.
Instead, they should be added to the container returned by
getContentPane() method. The default layout
manager of this content pane is
java.awt.BorderLayout. Unlike its
java.awt.Dialog superclass,
JDialog can display a menubar. Specify one with
setJMenuBar().
setDefaultCloseOperation() specifies how the
JDialog should behave when the user attempts to
close it. The argument should be one of the constants defined by the
WindowConstants interface. The default is
HIDE_ON_CLOSE.
JDialog uses a native window. Use
JInternalFrame for lightweight dialogs.

This class is a subclass of
javax.swing.text.JTextComponent that can be
easily configured to display and edit different formatted-text
content types using a
javax.swing.text.EditorKit object. To configure
a JEditorPane, call
setEditorKit() to specify an appropriate editor
kit for the desired content type. Alternatively, use the static
registerEditorKitForContentType() to register a
mapping between content types and their corresponding editor kits and
then call setContentType(). With such a mapping in
place, you may also use setPage() to specify a URL
to be displayed. The JEditorPane determines
the content type of the URL, installs an appropriate
EditorKit, and loads the contents of the URL into
the JEditorPane.
Swing comes with two predefined EditorKit
subclasses: javax.swing.text.html.HTMLEditorKit
and javax.swing.text.rtf.RTFEditorKit.

Returned By: javax.swing.text.StyledEditorKit.StyledTextAction.getEditor()

JFileChooser

Java 1.2

javax.swing

serializable accessible swing component

This component allows the user to select a file. After creating a
JFileChooser component, and setting any desired
properties, the easiest way to use it is to call
showOpenDialog() or
showSaveDialog(). These methods display the
JFileChooser in a modal dialog box, using the
component you specify as its parent. They also customize the
"Okay"
button to read Open or Save (or locale-appropriate equivalents). You
can also call showDialog() and explicitly specify
the text to appear in the "Okay" button. The methods return
APPROVE_OPTION if the user selects a file and
clicks the Save or Open button. They return
CANCEL_OPTION if the user clicks the Cancel button or otherwise dismisses the dialog.
They return ERROR_OPTION if some sort of error or
exception occurs during file selection. When the return value is
APPROVE_OPTION, you can call
getSelectedFile() to obtain a
File object that represents the file the user
selected.

Other commonly used JFileChooser properties are
currentDirectory, which specifies the initial or
most recently selected directory displayed by the
JFileChooser, and
fileSelectionMode, which specifies whether the
JFileChooser should allow the user to choose a
file, a directory, or either. The legal values for the
fileSelectionMode property are
FILES_ONLY, DIRECTORIES_ONLY, and
FILES_AND_DIRECTORIES.

You can selectively filter files, so that only certain choices are
displayed to the user, by passing a
javax.swing.filechooser.FileFilter object to
setFileFilter(). This allows you, for example, to
tell the JFileChooser to display only files that
have an extension of .htm or
.html. The default
FileFilter is one that display all files. You can
obtain an instance of it by calling
getAcceptAllFileFilter(). You can
provide a set of file filters for the user to choose from by
setting the choosableFileFilters
property to an array of FileFilter objects.

In addition to file filters, JFileChooser provides
another powerful
way to customize the file selection dialog. The
accessory property allows you to specify a
JComponent file selection accessory to be
displayed within the JFileChooser. Such
accessories are typically used as file previewers. For example, you
might write an
accessory to display a thumbnail version of a
selected image file. The accessory object must register a
PropertyChangeListener on the
JFileChooser, so that it can receive notification of
changes in the selectedFile property.

This class is used to display the main window (or windows) of a Swing
application. Every JFrame has a single
automatically created JRootPane child. You should
not add children directly to the JFrame, but
instead call getContentPane() and add children to
the container returned by that method. Similarly, if you set a layout
manager, you should do so on the container returned by
getContentPane(). The default layout manager for
this container is an instance of
java.awt.BorderLayout.

The JFrame has two other features of interest.
First, setJMenuBar() automatically places a
specified menubar at the top of the window, leaving the content pane
free for other application content. Second,
setDefaultCloseOperation() specifies how the window
should respond when the user attempts to close it (e.g., by
typing Alt-F4 in Windows). The
argument to this method should be one of the constants defined by
javax.swing.WindowConstants. The default is
HIDE_ON_CLOSE.
In addition to these features, JFrame also inherits
useful methods from java.awt.Frame, including
setCursor(), setIconImage(),
setResizable(), and setTitle().

JFrame uses a heavyweight native window. To
create a lightweight
window that appears entirely within the confines of a containing
window, you can use JInternalFrame.

This class is a lightweight Swing component that simulates a
heavyweight native window, complete with titlebar and other window
decorations appropriate to the installed look-and-feel. Because it is
a lightweight component, with no native window of its own, a
JInternalFrame is constrained to stay within the
bounds of its container. This container is
typically a JDesktopPane. Within a
JDesktopPane, a JInternalFrame
can be moved, resized, iconified, and maximized, much like a
JFrame can be.

JInternalFrame is like JFrame in
many ways. A JInternalFrame has a
JRootPane as its only child. Components should not
be added directly to a JInternalFrame, but rather
to the container returned by getContentPane().
setJMenuBar() specifies a menubar for the
lightweight window, and setDefaultCloseOperation()
specifies how it should respond when the user closes it. See
JFrame for more on these two methods.

setTitle() sets the title displayed in the internal
frame's titlebar. setFrameIcon() specifies a small
image to be displayed in the titlebar and possibly also in the
iconified representation of the JInternalFrame.
setIconifiable() specifies whether the user is
allowed to iconify the window, setIcon() actually
iconifies or deiconifies the window, and isIcon()
queries whether the window is currently iconified.
setDesktopIcon() specifies the internal
JInternalFrame.JDesktopIcon object used to
represent the iconified version of the
JInternalFrame. This last method should not be
used by application-level code.

Similarly, setMaximizable() specifies whether the
user can maximize the window, and setMaximum()
maximizes the window. setResizable() specifies
whether the window can be resized. setSelected()
selects or deselects the window, and toFront() and
toBack() move the window to the top and bottom of
the stacking order relative to other JInternalFrame
windows. Finally, as with all components,
setVisible() makes the window visible or invisible.

This inner class represents an iconified version of a
JInternalFrame to be displayed by a
JDesktopPane. The appearance of the
JDesktopIcon is left entirely to the current
look-and-feel, and JDesktopIcon does not define any
properties you can set to change its appearance.
JDesktopIcon may be removed in future versions of
Swing; it should not be used by application-level code.

This class displays a short string of text and/or an
Icon. JLabel is a
display-only component with no behavior, so the displayed
text and/or icon does not respond to any input events.
JLabel
does not maintain any state and therefore does not use a model. By
default, a JLabel displays a single line of text in
a single font. However, as of Swing 1.1.1 and Java 1.2.2, if the text property
begins with "<html>", the label is formatted as HTML
text and may contain multiple fonts and multiple lines.

The icon, text, and
font properties need no explanation.
disabledIcon specifies an alternate icon to display
when the JLabel is disabled. By default, a grayscale
version of the regular icon is used.
horizontalAlignment and
verticalAlignment specify the justification of the
label, and horizontalTextPosition and
verticalTextPosition specify the position of the
text relative to the icon. Each of these properties should be set to one
of the LEFT, CENTER,
RIGHT, TOP, or
BOTTOM constants defined by the
SwingConstants interface. The
iconTextGap property specifies the number of pixels
between the text and the icon.

Although JLabel does not have any behavior of its
own, it can display a mnemonic character. If the
displayedMnemonic property is set, the specified
character is underlined in the label. If the
labelFor property refers to another component,
the JLabel requests keyboard focus for that
component when the mnemonic is used. This is useful for labeling
JTextField components, for example.

This class is a Swing container that layers its children according to
a specified stacking order. When you add a child to a
JLayeredPane, you specify an
Integer as the constraints argument to the
add() methods. This Integer
object specifies the layer number for the child, where higher numbers
are nearer the top of the stack. JLayeredPane
defines a number of _LAYER constants as predefined
layers. The layer of a child can also be set with
setLayer(). If multiple children are in the same
layer, their relative stacking order is determined by their insertion
order. This position within a layer can be modified with
setPosition(),
moveToFront(), and moveToBack().
JLayeredPane is typically used without a layout
manager; children have their size and position explicitly set.

All JFrame, JDialog,
JApplet, and JInternalFrame
objects contain a JRootPane which, in turn,
contains a JLayeredPane. This internal
JLayeredPane is used to correctly layer lightweight
menus, dialogs, floating palettes, internal frames, and so forth.

This class displays a list of items (typically strings)
and allows the user to select one or more of them. The objects to be
displayed are stored in a ListModel object. Two
JList constructors allow list items to be
specified as a static array or Vector of objects,
however. For a dynamic list of elements, you may want to use your own
instance of DefaultListModel, which maintains a
Vector-like list of objects.
By default, JList displays lists of strings. To
display other types of list items, define an appropriate
ListCellRenderer class and pass an instance of it
to setCellRenderer().

The selection state of the JList is
maintained by a ListSelectionModel object. By
default, JList uses a
DefaultListSelectionModel object.
Application programmers rarely need to work with the
ListSelectionModel directly because
JList provides a number of methods to query and set
the selection state. setSelectionMode() specifies
the types of selections allowed by the JList. Its
argument should be one of the three constants defined by
ListSelectionModel.
SINGLE_SELECTION allows only a single item to
be selected, while SINGLE_INTERVAL_SELECTION
allows multiple items in a single contiguous block to be selected and
MULTIPLE_INTERVAL_SELECTION allows any number
of items, contiguous or not, to be selected.

JList generates a
javax.swing.event.ListSelectionEvent when the
selection state changes and sends it to the
valueChanged() methods of any registered
javax.swing.event.ListSelectionListener
objects.

This class implements a pulldown menu in a menubar or a
pull-right menu nested within another menu. As a subclass of
JMenuItem, JMenu is effectively
a menu button with an associated JPopupMenu that
appears when the button is activated.
Menu items can be added to a JMenu with the
add(), insert(),
addSeparator(), and
insertSeparator() methods. Note that you can add
String and Action objects in
addition to regular JMenuItem objects. In these
cases, an appropriate JMenuItem is automatically
created for the String or
Action.
JMenu generates a
javax.swing.event.MenuEvent when it is selected
and when its menu is popped up or down.
The default JMenu model is
DefaultButtonModel.

This protected inner class is a
java.awt.event.WindowListener that is used
internally by JMenu to determine when the popup
window containing the menu items closes. Application-level code never
needs to use this class.

This class implements a menu bar. JMenu objects
are placed in a JMenuBar with the
add() method and can be removed with the
remove() methods. A Help menu should be singled out for special
treatment (typically by placing it at the right-hand edge of the menu
bar) with setHelpMenu().
JMenuBar uses a
SingleSelectionModel object to keep track of which
of its JMenuItem children (if any) is currently
selected. By default, JMenuBar uses a
DefaultSingleSelectionModel model object.

In AWT, the MenuBar class is not a
Component. In Swing, JMenuBar
is a JComponent and can be laid out in an
application like any other component. Note, however, that
JFrame, JDialog,
JApplet, and JInternalFrame all
have setJMenuBar() methods that automatically
position a JMenuBar at the top of the window. This
is the easiest and most common way to lay out a menu bar.

This class implements an item in a pulldown or popup menu. As a
subclass of AbstractButton, it shares most of the
properties of JButton. One new feature is that it
allows an
accelerator to be specified. An accelerator is a keyboard binding
for the menu item. Like all Swing buttons,
JMenuItem also supports a mnemonic. Accelerators
differ from mnemonics in two important ways, however. First,
accelerators can be used at any time, while menu item mnemonics can
be used only when the menu that contains them is displayed. Second,
accelerators are specified with a KeyStroke object,
rather than a simple character. This allows complex bindings
that include function keys and arbitrary modifier keys.

In addition to its AbstractButton functionality,
JMenuItem also implements the
MenuElement interface.
The default JMenuItem model is
DefaultButtonModel, and the UI
delegate class is MenuItemUI.

This component is used to display various
types of simple dialog boxes to the user (yes, its name is misleading).
It is almost always used
through one of the
showXXXDialog() static methods.
The fact that there are more than 20 of these methods demonstrates the
highly-configurable nature of this class. The
showInternalXXXDialog()
methods display dialogs in
lightweight JInternalFrame windows. The other
static methods display methods in heavyweight
JDialog windows.

You can create and display a simple message dialog with
showMessageDialog() and
showInternalMessageDialog(). These methods display
a dialog box that contains the specified message, an optional icon, and
an Okay button that dismisses the
dialog. The dialog is modal, meaning it blocks, returning
only when the user has dismissed the dialog. The
parentComponent argument specifies the
component that serves as the parent of the dialog (the dialog
typically pops up over this component), while
title specifies a string to appear
in the titlebar of the dialog.
The message argument is more complex. It
is declared as an Object. You typically pass a
String value, which is automatically displayed in a
JLabel. However, you can also specify an
Icon, which is also displayed in a
JLabel, or any
JComponent, which is displayed as is.
Furthermore, instead of specifying a single message object, you can
specify an array of objects that contains any combination of strings,
icons, and components.
The messageType argument must be one of the
constants WARNING_MESSAGE,
QUESTION_MESSAGE, INFO_MESSAGE,
ERROR_MESSAGE, or
PLAIN_MESSAGE. These constants specify the basic
type of message you are displaying. The current look-and-feel may
customize the appearance of the dialog based on this value.
Typically, the customization is limited to the display of one of a
standard set of icons. If you'd like to override the default icon for
the dialog, you can also explicitly specify an
icon argument.

The showConfirmDialog() and
showInternalConfirmDialog() methods are much like
showMessageDialog() and
showInternalMessageDialog(), except that
they ask the user to make a choice and provide several push buttons
that represent the options available to the user. (It is the
options represented by these buttons from which the name
JOptionPane derives.) For example,
showConfirmDialog() can be used to display a
dialog that asks "Do you really want to quit?" and allows the user to
respond by pushing either a Yes button
or a No button.
The parentComponent,
title, message,
messageType, and icon
arguments to these methods are the same as for the message dialogs.
The confirm dialogs add an optionType argument
and a return value. optionType specifies
which buttons should appear in the dialog. It should be
one of the constants DEFAULT_OPTION,
YES_NO_OPTION,
YES_NO_CANCEL_OPTION, or
OK_CANCEL_OPTION.
DEFAULT_OPTION provides a single Okay button; the others provide buttons as
indicated by their names.
Like the message dialogs, the confirm dialogs are modal, and the static
methods that display them block until the user has dismissed the dialog.
Since confirm dialogs present choices to the user, they have return
values that indicate the choice the user selected. This return value
is one of the constants OK_OPTION,
CANCEL_OPTION, YES_OPTION,
NO_OPTION, or CLOSED_OPTION.
This last value indicates that the user closed the dialog window
without selecting any of the available buttons; typically, it should be
treated as a CANCEL_OPTION response.

showOptionDialog() and
showInternalOptionDialog() are generalizations of
the confirm dialog. They take an options
argument, which specifies what buttons to display in the dialog box,
and an initialValue argument, which specifies
which of these buttons should be the default button. The
options argument is an array of objects.
Typically, you specify string values that the
JOptionPane displays in JButton
components. You can provide arbitrary components in the
options array, but if you do so, you must
arrange for each component to update the state of the
JOptionPane by calling its
setValue() method when selected.

The final category of dialogs are the input dialogs, created with
showInputDialog() and
showInternalInputDialog(). Most versions of these
methods take the same arguments as the message dialogs. However, in
addition to displaying a message, they also contain a
JTextField in which the user can enter
whatever input value is requested. These dialogs are modal, and the
methods that display them block until the user has dismissed the dialog.
If the user dismisses the dialog with the Okay button, the methods return the user's input
as a String. If the user dismisses the dialog with
the Cancel button, these methods return
null.
One version of both showInputDialog() and
showInternalInputDialog() are different. These
methods take additional selectionValues and
initialSelectionValue arguments. Instead
of asking the user to enter a string, they ask the user to choose
among the values contained in the
selectionValues array (presenting
initialSelectionValue as the default value).
The display of these values is left to the current look-and-feel,
although they are typically displayed using a
JComboBox or JList component.
The selectionValues array typically
contains strings, but it may also contain Icon
objects or other objects that can be meaningfully displayed by
JList and JComboBox components.
When you pass an array of selectionValues to
showInputDialog() or
showInternalInputDialog(), the return value is the
value the user has chosen or null, if the user selected
the Cancel button.

Instead of using one of the static methods to display a
JOptionPane dialog, you can also create a
JOptionPane component, set properties as desired,
and then create a dialog to contain it by calling the
createDialog() or
createInternalFrame() instance method.

This component is a lightweight container that is commonly
used to group other components within graphical user interfaces. Use
setLayout() to specify a
java.awt.LayoutManager to control the arrangement
of components within the JPanel.
Various JPanel() constructors make it easy to set
the values of the inherited layout and
doubleBuffered properties.

This JTextField subclass is designed for entering
passwords and other sensitive data. It does not display the
characters of the entered text, preventing it from being read by
onlookers. Use setEchoChar() to specify the
character that should appear (e.g., an asterisk)
in place of the characters entered by the
user.

JPasswordField overrides and deprecates the
getText() method of JTextField.
Instead, use getPassword() to obtain the user's
input. This method returns an array of characters
instead of an immutable String object. This means
that after you use the password, you can set the elements of the array
to 0 for additional security.

This component displays a menu of choices in a popup window. It is
used both for standalone popup menus that are posted when the user
clicks the right mouse button and for the pulldown and pull-right
menus that appear when the user selects a JMenu
component.
JPopupMenu uses a
SingleSelectionModel to maintain its selection
state.

After you create a JPopupMenu object, you can
add items to it
with the add() and
addSeparator() methods. The
java.awt.event.ActionListener of a menu item is
notified when that item is selected. After adding items to the
menu, you can pop it up at a specified location with the
show() method. This is usually done only after
calling the isPopupTrigger() method of a
java.awt.event.MouseEvent object. The menu
automatically pops itself down when the user selects an item or stops
interacting with it.
Call setLightWeightPopupEnabled() to specify
whether the popup should use a lightweight window or a heavyweight
native window. Call the static
setDefaultLightWeightPopupEnabled() to specify a
default behavior for all popup menus.

This inner class is a JSeparator component
customized for use in JPopupMenu components. The
addSeparator() method of
JPopupMenu returns an instance of this class.
This class is a trivial subclass of JSeparator that
does nothing except to override the UI delegate class name and ensure
that the separator is never vertical.
Application-level code never needs to use this class.

public static class JPopupMenu.Separator extends JSeparator {

//

Public Constructors

public Separator ();

//

Property Accessor Methods (by property name)

public String getUIClassID ();

Overrides:JSeparator

}

JProgressBar

Java 1.2

javax.swing

serializable accessible(value) swing component

This class implements a progress bar: a component that graphically
displays a non-adjustable integer value. It is typically used to
display a program's progress on some time consuming task, but can also
be used to simulate the display of a graphic equalizer, for example.
ProgressMonitor is a useful class that displays a
JProgressBar in a dialog box.

Like JScrollBar and JSlider,
JProgressBar uses a
BoundedRangeModel to maintain its state.
The value property is the most important; it
specifies the currently displayed value.
JProgressBar fires a
javax.swing.event.ChangeEvent when its
value property changes. value
must be between the minimum and
maximum values. The orientation
property should be one of the HORIZONTAL or
VERTICAL constants defined by
SwingConstants. Set the
borderPainted property to false
if you do not want the JProgressBar to display a
border around itself.

This class implements a radio button: a toggle button with
default graphics that indicate mutually exclusive behavior.
Because JRadioButton supplies its own default and
selected icons, you typically do not use the constructors that take
Icon arguments. The selection state of a
JRadioButton is stored in a
JToggleButton.ToggleButtonModel object by default.
The initial selection state can be specified in the call to the
constructor. The current state can be set with
setSelected() and
queried with isSelected().

The default graphics of the JRadioButton are
designed to indicate to the user that the button represents one of a
group of mutually exclusive choices. (The name "radio button" refers
to the mechanical station-preset buttons on old-style car
radios: only one button could be pressed at a time.)
JRadioButton does not implement or enforce mutual
exclusion; this is done by adding JRadioButton
components to a ButtonGroup object.

This class implements a radio button that appears within a pulldown or
popup menu. Its use is similar to that of
JRadioButton. Use isSelected()
to query the selection state of the menu
item and setSelected() to select or deselect
the item. By default, the selection state is stored in a
JToggleButton.ToggleButtonModel object.
Note that JRadioButtonMenuItem, like
JRadioButton, does not implement mutually exclusive
selection behavior on its own. Each
JRadioButtonMenuItem in a mutually exclusive
selection group must be added to a corresponding
ButtonGroup object. It is this
ButtonGroup that enforces mutual exclusion.

This component is used internally by all the top-level Swing
containers: JWindow, JFrame,
JDialog, JApplet, and
JInternalFrame. Most applications can simply use
these top-level containers; they never need to use
JRootPane directly.

JRootPane is a container that manages a fixed
hierarchy of children, including a content pane and an optional
menubar. You cannot add children directly to a
JRootPane; instead, you must add them to the
container returned by its getContentPane() method.
Each of the top-level Swing containers that uses a
JRootPane also provides a
getContentPane() method that returns the content
pane of its JRootPane. Similarly, to add a
menubar to a JRootPane or top-level container
that uses JRootPane, you can use the
setJMenuBar() method. JRootPane
has a custom layout manager that manages its various children. You
should not try to set your own layout manager on a
JRootPane--instead, set it on the content pane.

The content pane and menubar are not actually direct children of the
JRootPane. Instead, they are children of a
JLayeredPane that is itself a child of the
JRootPane. The JLayeredPane of
a JRootPane provides the layering features required
for Swing to implement modal dialogs, floating palettes, popup menus,
tooltips, and drag-and-drop-style graphical effects. These features
are used internally by Swing; only very advanced applications
need to use them directly.

In addition to its JLayeredPane, a
JRootPane also contains another child, known as the
glass pane. This child fills the entire
JRootPane and sits on top of the
JLayeredPane. The glass pane either must be hidden or
must be a transparent component. Otherwise it obscures all other contents
of the JRootPane. The glass pane can be used both to
intercept mouse events destined for other components within the
JRootPane and for the temporary
display of graphics on top of the components of a
JRootPane. Again, these glass pane features are
used internally by Swing, and only advanced applications
need to use them directly.

This class implements a scrollbar component that can be used to scroll
the visible region of some entity, within a maximum and a minimum range. The
minimum and maximum properties
specify the range within which scrolling takes place. The
value property specifies the current value of the
scrollbar--the beginning of the visible region.
visibleAmount specifies how much of the range
is visible at once
and also specifies the size of the displayed thumb, or knob,
of the scrollbar. The values of these properties are all stored in a
BoundedRangeModel object.
JScrollBar uses
DefaultBoundedRangeModel by default.
(The visibleAmount property corresponds to
the extent property of
BoundedRangeModel.)
The orientation property specifies whether the
JScrollBar is a horizontal or a vertical scrollbar.
Use either the HORIZONTAL or
the VERTICAL constant defined by the
SwingConstants interface.
unitIncrement specifies the amount by which the
scrollbar thumb should move when the user clicks on the arrows at
either end of the scrollbar. The default is 1. The
blockIncrement property specifies the amount that
the scrollbar should move when the user scrolls a block at a time (how
this is accomplished varies in different look-and-feels).

JScrollBar fires a
java.awt.event.AdjustmentEvent when one of the
value,
minimum, maximum,
visibleAmount, or
valueIsAdjusting properties changes.
Some programs may prefer to instead handle the
javax.swing.event.ChangeEvent events generated
by the model of the JScrollBar. In either case, if
the valueIsAdjusting property of the
JScrollBar or its model is
true, the change is one in a series of
changes. Listeners that prefer not to track these transient changes
can ignore events when valueIsAdjusting is
true.

This class is a container that allows a child component to be scrolled
horizontally and vertically. The component to be scrolled is not a
direct child of the JScrollPane, so it must not be
added directly with the add() method. Instead, it
is a child of a JViewport contained within the
JScrollPane. You specify the component to be
scrolled by passing it to the JScrollPane()
constructor or to the setViewportView() method.
Any type of component can be used within a
JScrollPane, but components that implement the
Scrollable interface work best.
The horizontalScrollBarPolicy and
verticalScrollBarPolicy properties control the
policy for displaying scrollbars. The legal values are the various
ALWAYS, AS_NEEDED, and
NEVER constants defined by the
ScrollPaneConstants interface. Another useful
property is viewportBorder, which allows you to
specify a border to appear around the JViewport
that contains the component being scrolled.

In addition to the main scrolled component,
JScrollPane supports column header and row
header components. The column header appears above the main
scrolling component and scrolls horizontally, but not vertically, so
that it is always visible at the top of the
JScrollPane. Similarly, the row header component
scrolls vertically but not horizontally, so it is always visible at
the left of the JScrollPane. Specify the row and
column header components with setColumnHeaderView()
and setRowHeaderView().
The JScrollPane can also display arbitrary
components in each of its four corners. Use
setCorner() to specify a component for a corner.
The ScrollPaneConstants interface defines constants
that specify which corner a component should appear in. Note that the
space available in the corners of a JScrollPane is
determined by the width of the scrollbars and the widths of the
column and row headers, if any.
The layout management of the scrollable
JViewport, the scrollbars, the column and row
headers, and the corners is provided by the
ScrollPaneLayout class, a specialized
java.awt.LayoutManager.

See also the JScrollBar and
JViewport components, the
ScrollPaneLayout layout manager, and the
Scrollable and
ScrollPaneConstants interfaces.

This protected inner class is a trivial subclass of
JScrollBar that is used for the scrollbars of a
JScrollPane. This subclass exists for two simple
reasons: to implement the
javax.swing.plaf.UIResource interface and to make
the scrollbars work with the Scrollable interface.
Application-level code never needs to use this class.

This simple component draws a horizontal or vertical line that is as
wide or as tall as the component itself. The
orientation property is the only property of
interest. It should be SwingConstants.HORIZONTAL
or SwingConstants.VERTICAL. There are no
properties controlling the thickness, color, or other attributes of the
JSeparator.
Separator objects are commonly used in JPopupMenu
and JToolBar components. Note, however, that these
components define addSeparator() methods and
implement custom subclasses of JSeparator. These
custom subclasses have their own UI delegate subclasses, which allows
them to provide a visual appearance precisely tailored for menus and
toolbars.

This class implements a component that allows the user to drag a
knob, or pointer, in order to graphically adjust an integer value. The
minimum and maximum properties
specify the range of the slider, and the value
property specifies the current value. extent
specifies the width of the knob and also an adjustment increment.
The values of these properties are maintained by a
BoundedRangeModel object. By default,
JSlider uses a
DefaultBoundedRangeModel object.
orientation specifies the orientation of the
slider; it should be one of the SwingConstants
values HORIZONTAL or VERTICAL.
If the inverted property is
true, the range is inverted to run from
right to left or from top to bottom.

A JSlider can display optional tick marks and
labels along its length. The paintTicks and
paintLabels properties specify whether they should
be displayed. majorTickSpacing and
minorTickSpacing specify the spacing of long and
short tick marks. Note that these spacings are measured in the
coordinate space defined by the JSlider minimum
and maximum value; they are not pixel spacings. If the
snapToTicks property is set
true, the user can only adjust the
value property to a value at which a tick mark
appears.
If you set paintLabels and
majorTickSpacing, the JSlider
automatically
displays a numeric label for each major tick mark. You can call
createStandardLabels() to force this behavior, even
when tick marks are not displayed. You can also specify custom labels
by setting the labelTable property to a
java.util.Dictionary that maps
Integer coordinates to
JComponent labels.

A JSlider fires a
javax.swing.event.ChangeEvent when one of its
value,
maximum, minimum,
extent, or valueIsAdjusting
properties changes. If valueIsAdjusting is
true when an event is fired, it means that the
event is one of a series of changes. Listeners that do not want to
track these rapid-fire transient changes can ignore them.

This class is a container that splits itself horizontally or
vertically to display two children. The orientation of the pane is
specified by the orientation property, which
should be set to either the HORIZONTAL_SPLIT or
VERTICAL_SPLIT constant. The two children are
specified by a pair of properties that depend on the orientation of
the JSplitPane. If the orientation is
HORIZONTAL_SPLIT, the children are specified
with setLeftComponent() and
setRightComponent(). For a
VERTICAL_SPLITJSplitPane, the
children are specified with setTopComponent() and
setBottomComponent().
The position of the divider between the two panes of a
JSplitPane can be set with
setDividerLocation(). The argument can be an
integer that specifies a pixel position or a double
between 0.0 and 1.0 that specifies a percentage of the size of the
JSplitPane.

JSplitPane allows the user to adjust the relative
sizes of the two children by dragging the divider that appears between
the children. The adjustment is constrained, however, so that a child
is never made smaller than its specified minimum size. If the
continuousLayout property is set to
true, the children are resized
continuously while the user drags the divider. If this property is
false, however, the child components are not
resized until the user finishes the drag.
Although the divider location of a
JSplitPane can be thought of in terms of the
BoundedRangeModel, the
JSplitPane implementation does not use a separate
model object.

JTabbedPane is a container that can contain any
number of children. It displays one child at a time, but displays a
tab for each child. The user can click on these tabs to adjust the
currently displayed child. JTabbedPane uses a
SingleSelectionModel to keep track of the currently
selected and displayed child.
By default, the tabs appear at the top of
the JTabbedPane. You can override this default,
however, with setTabPlacement(). The argument to
this method should be one of the TOP,
BOTTOM, LEFT, or
RIGHT constants defined by the
SwingConstants interface.

Although you can add children to a JTabbedPane
with the standard add() methods, this does not give
you much flexibility in specifying the contents of the tab for that
child. Instead, JTabbedPane provides several
addTab() methods that allow you to specify the
child along with the String, Icon,
and tooltip text to use for its
tab. A corresponding insertTab() method allows you
to specify a child, the contents of its tab, and the position of the
tab within the list of tabs. Use
setSelectedComponent() or
setSelectedIndex() to specify which child is
currently displayed.
setEnabledAt() allows you to enable or disable a
tab, specified by its position within the list of tabs.
setDisabledIconAt() allows you to specify an icon
to display when a tab is disabled. Various other methods whose names
end with "At" allow you to alter properties of individual tabs,
specified by position.

This protected inner class is a trivial
ChangeListener implementation used internally by
JTabbedPane to listen for changes from its
SingleSelectionModel. Applications never need to
use this class, and it probably should not have been made part of the
public API. If you want to use a different listener implementation,
override the createChangeListener() method of
JTabbedPane.

JTable is a powerful and complex Swing component
for displaying and editing tabular data. JTable
relies on the auxiliary classes and interfaces in the
javax.swing.table package.
Two JTable constructors exist that make it
easy to display tabular data that is stored in an
Object[][] or in a Vector of
rows, where each row is a Vector of cell values.
These convenience constructors take an additional array or
Vector of objects to be used as column headers for
the table. If your data is not already in one of these pure tabular
forms, you must provide a
javax.swing.table.TableModel object that enables
the JTable to find the value for each cell.
You typically do this by subclassing
javax.swing.table.AbstractTableModel.

When displaying a JTable that contains more than a
few rows or columns, it is common to place the
JTable within a JScrollPane.
JTable components created with the convenience
constructors or with a simple default subclass of
AbstractTableModel are not editable. However, you
can enable editing on a cell-by-cell basis by overriding the
isCellEditable() and
setValueAt() methods of the
AbstractTableModel.

Unlike most Swing components, JTable relies on more
than one associated model object. In addition to the
TableModel object that contains table data, a
JTable also uses a
TableColumnModel object to keep track of the
columns of the table and their ordering and selection state and a
ListSelectionModel used to keep track of selected
rows in the table.

The cell values returned by the TableModel are
generic objects. By default, JTable knows how to
display and edit String, Boolean,
and Number values. If you want to display another
type of objects, you can create a custom
javax.swing.table.TableCellRenderer object and pass
it to setDefaultRenderer(). If you want to allow
users to edit values of this type, you can create a custom
javax.swing.table.TableCellEditor and pass it to
setDefaultEditor().

JTextArea displays
multiple lines of plain, unformatted text and allows the user to
edit the text. The
JTextArea API is designed to be similar to the
java.awt.TextArea API.

You can specify the text to be displayed by passing a
String to the JTextArea
constructor or by using the setText() and
getText() methods inherited from the superclass.
Specify the number of rows and columns to be displayed by the
JTextArea by passing these values to the
constructor or by using the setRows() and
setColumns() methods. The
lineWrap property specifies whether long lines
should wrap. The wrapStyleWord property
specifies whether lines should wrap at word boundaries or at character
boundaries. If you are displaying
more than a few lines of text, you probably want to place your
JTextArea within a JScrollPane
to enable scrolling as needed.

JTextArea is a subclass of
javax.swing.text.JTextComponent and inherits many
features of that powerful text editor. Many of the most commonly used
JTextArea methods are actually inherited from its
superclass. They include the getText() and
setText() methods already mentioned, as well as
setEditable(),
getCaretPosition(), and
setCaretPosition().
Like its superclass, JTextArea uses a
javax.swing.text.Document object as its model.
Since a JTextArea displays only plain text, however,
you can typically use a simple String object instead.

JTextField allows the user to enter and edit a
single line of plain text. JTextField is designed
to supersede java.awt.TextField, so it has a similar
API.
You can set and query the text
with the setText() and
getText() methods inherited from the superclass.
Use setFont() to specify the font in which the text
is displayed. Use setColumns() to set the
number of characters in the field. Note that the specified number of
columns is approximate unless you are using a monospaced font.
Note that JTextField inherits a number of useful
properties from its superclass. These include
enabled, editable,
caretPosition, and selectedText.

JTextField fires an ActionEvent
to any registered ActionListener objects when the
user types Enter. You can specify the
action command text sent with the ActionEvent by
calling setActionCommand().

JTextPane is a component for displaying and
editing multiline formatted text. When combined with a GUI that
allows the user to select fonts, colors, paragraph styles, and so
forth, it provides substantial word-processing functionality for any
Java application.
JTextPane works with documents that implement the
javax.swing.text.StyledDocument interface,
typically a DefaultStyledDocument.
JTextPane also relies on
javax.swing.text.StyledEditorKit to provide
auxiliary configuration information.

JTextPane does not directly define methods for
inserting styled text into the document. You must work directly with
the StyledDocument to do that.
JTextPane allows the user to edit text but
does not provide any means for the user to specify or change the style
of that text. Your application must provide additional GUI components
(e.g., a menu of available styles or a dialog box for selecting a
font) in order to allow the user to select styles.

Call setCharacterAttributes() to specify
attributes, such as font size and style, that apply to individual
characters. This method either sets the attributes of the
currently selected text, or, if there is no selection, specifies
attributes to be applied to text inserted in the future. The boolean
replace argument indicates whether these
attributes should replace the previous attributes or should augment
them. setParagraphAttributes() is a similar
method, but it sets attributes, such as margins and justification,
that apply to entire paragraphs of text.

In addition to displaying formatted text, JTextPane
can also display images and arbitrary components.
JTextPane provides the
insertComponent() and
insertIcon() methods to make it easy to insert
objects of these types without having to manipulate the
StyledDocument object.

This class implements a toggle button: a button that can be
selected or deselected. The user can toggle between the selected and
deselected states by clicking the button. Like all Swing buttons, a
JToggleButton can display text and an icon. The
selection state is typically indicated by the button border and
background color. You can also
call setIcon()
and setSelectedIcon() to specify different icons
for the default and selected states.
By default, JToggleButton keeps track of its
selection state with a
JToggleButton.ToggleButtonModel object.
JToggleButton is less commonly used than its
subclasses JCheckBox and
JRadioButton.

This class is the ButtonModel used by default
by JToggleButton, JCheckBox, and
JRadioButton components. It overrides several
methods of DefaultButtonModel in order to delegate
button selection state information to a ButtonGroup
object. Applications typically never need to instantiate this class.

JToolBar is a container that displays a row or
column of children, typically JButton children, that
represent application tools or actions. JToolBar
has two special features that make it useful in applications.
First, it
has a special add() method that allows you to add
an Action object, rather than a
Component, to it. When you do this, an appropriate
JButton is automatically created. This
created button tracks the enabled state of the action,
so if the action is disabled, the button becomes disabled as well.
The JMenu class has this same ability to accept
Action objects as children; the commonly used
actions of an application frequently appear in both
JMenu and JToolBar components of
the application.
A JToolBar can contain special separator components
that serve to group related tools and separate unrelated tools. You
can add a separator to a JToolBar with the special
addSeparator() method.

The second special feature of JToolBar is that it
is draggable. Unless this feature has been disabled with
setFloatable(), a JToolBar
displays a special grip that the user can use to drag the toolbar.
If the user drags the toolbar out of the window in which it appears, it
becomes a floating palette in a window of its own. Additionally, if
the JToolBar is positioned against one edge of a
container that uses a java.awt.BorderLayout layout
manager and if there are no other components positioned
against the edges, the user can drag the
JToolBar to any other edge of the container. The
conventional orientation and position for a
JToolBar is a horizontal row of controls positioned
just below the menubar at the top of a window. By dragging the
JToolBar, however, a user can automatically convert
it to a vertical toolbar positioned against the left edge of the
window, for example.

JToolBar defines only a few interesting properties.
As mentioned earlier, floatable specifies whether the
user can drag the JToolBar.
orientation specifies whether the
JToolBar arranges its children into a horizontal or
vertical bar. The value of this property should be one of the
SwingConstants constants
HORIZONTAL or VERTICAL. The
default is HORIZONTAL. Finally, the
margin property specifies the amount of space
between the border of the toolbar and its children.

This subclass of JSeparator defines a visual
separator component specially tuned for use within a
JToolBar. Practically speaking, this class is no
different than JSeparator. You should rarely need
to explicitly create or work with a
JToolBar.Separator. Just call
JToolBar.addSeparator() as needed to create
separators and add them to a JToolBar.

public static class JToolBar.Separator extends JSeparator {

//

Public Constructors

public Separator ();

public Separator (java.awt.Dimension size);

//

Property Accessor Methods (by property name)

public java.awt.Dimension getMaximumSize ();

Overrides:JComponent

public java.awt.Dimension getMinimumSize ();

Overrides:JComponent

public java.awt.Dimension getPreferredSize ();

Overrides:JComponent

public java.awt.Dimension getSeparatorSize ();

default:DimensionUIResource

public void setSeparatorSize (java.awt.Dimension size);

public String getUIClassID ();

Overrides:JSeparator

}

JToolTip

Java 1.2

javax.swing

serializable accessible swing component

JToolTip is the component used to display tooltips
in Swing applications. To display a tooltip over a component, simply
call setToolTipText() over that component. You
rarely or never need to work with the JToolTip
class itself. If you want to customize the appearance of the tooltip
displayed by a component, you can override the
createToolTip() method of that component, to return
your own JToolTip object.

JTree is a powerful Swing component for displaying
hierarchical, tree-structured data in outline form. The user can
expand and collapse the outline to show or hide the children of
any node in the tree. The user can also select and optionally edit
the values displayed in the tree.

JTree relies on the classes and interfaces in the
javax.swing.tree package. Most importantly, it
uses a TreeModel object to encapsulate the tree
data it displays. If your data already has a hierarchical structure,
you should implement a TreeModel class to serve as
an intermediary between your data structures and the
JTree component. If your data is not implicitly
hierarchical, you can arrange it into a hierarchy by implementing the
TreeNode or
MutableTreeNode interface or by encapsulating
your objects within DefaultMutableTreeNode objects
that implement these interfaces for you. Once you have done this,
you can rely on the default JTree model,
DefaultTreeModel.

JTree also defines constructors that accept tree
data in the form of an Object[], a
Vector, or a Hashtable. If your
data is relatively simple and you can express it in one of these forms,
it is easy to use one of these
constructors to display your data. If you specify a vector or
object array, the elements of the vector or array become the
nodes of the tree. If any of those elements are a vector, array, or
hashtable, the contents of that element become the children of
that node. If you specify a Hashtable, the
keys of the hashtable become the nodes of the tree and the values of
the hashtable become the children of those nodes. This is
particularly useful, of course, if the hashtable values are arrays or
vectors.

By default, tree nodes are not editable. You can change this, however,
with the setEditable() method. The selection state
and selection mode of a JTree is maintained by a
javax.swing.tree.TreeSelectionModel object. By
default, JTree uses a
DefaultTreeSelectionModel object. You can set your
own object with setSelectionModel(). Use the
setSelectionMode() method of the
TreeSelectionModel to specify the type of
selection that is supported by the JTree. To disable
selection in a JTree altogether, pass
null to setSelectionModel().

JTree defines a number of methods for setting and
querying the current selection state of the tree. It also defines
methods for collapsing and expanding nodes and for querying nodes to
determine whether they are expanded. These
methods use two different techniques for referring to a particular
node in the tree. One technique is to specify the integer row number
at which the item appears. While this is a convenient way to refer to
an item that the user has selected, for example, it does not map
naturally to an item in the TreeModel. The other
way to refer to an item in a JTree is with a
javax.swing.tree.TreePath object. A
TreePath is essentially an array of objects that
contains the node itself and all of its ancestors up to the root of
the tree. The first element in the array is the root, and the last
element is the tree node that is being referred to. The methods
getPathForRow() and
getRowForPath() allow you to convert from
one node representation to another. Related methods convert between X,
Y coordinates (such as the coordinates contained in a
MouseEvent) and the nearest
TreePath or tree row.

JTree displays its nodes using a
javax.swing.tree.TreeCellRenderer object. By
default, it uses DefaultTreeCellRenderer, which
displays any object in the tree in text form by calling its
toString() method. If you want to display custom
objects in a tree, you can implement your own
TreeCellRenderer and pass an instance to
setCellRenderer(). JTree does
not allow its nodes to be edited by default, but when editing is
enabled, it is done with a TreeCellEditor object.
The DefaultTreeCellEditor allows editing of
String and Boolean nodes. You
can implement your own TreeCellEditor if you
want to allow the user to edit other node types.

JTree defines quite a few methods for querying and
setting the state of the tree. The purpose of most of these methods
is fairly obvious. One thing to note is that different methods
use the word "visible" to mean different things. The methods
isVisible() and makeVisible()
use "visible" to refer to a node that is displayed under an
expanded parent. Under this definition, a node may be visible even
if it is currently scrolled off the screen. All other methods, such
as scrollPathToVisible(), use "visible"
to mean
that a node is actually on the screen and currently visible to the user.

JTree implements the Scrollable
interface, and, unless you are displaying a very small, fixed-size
tree, you should almost always place a JTree
within a JScrollPane container. If you are using
JTree to view a large amount of data, if all
the nodes are of the same type, and if the
TreeModel has an efficient implementation, you
may get better performance by passing true to
setLargeModel().

This subclass of
javax.swing.tree.DefaultMutableTreeNode is used by
the JTree constructors that accept tree data in
the form of a Vector, Hashtable,
or Object[]. The static
createChildren() method is used to populate a node
with the children contained in a specified Vector,
Hashtable, or array.
DynamicUtilTreeNode is dynamic in the sense that
it dynamically creates children nodes when those nodes are requested
for the first time.

This subclass of
javax.swing.tree.DefaultTreeSelectionModel defines
empty selection methods and is used
to disable selection in a JTree. You never need to
instantiate this class explicitly; simply pass null
to the setSelectionModel() method of
JTree.

This javax.swing.event.TreeSelectionListener
class is used internally
by JTree to redirect
javax.swing.tree.TreeSelectionEvent objects
so that they appear to
come from the JTree, rather than the
TreeSelectionModel object. Applications never need
to use this class.

This component displays a portion of the larger child component it
contains. It defines methods for efficiently scrolling the child
component within the viewable area. Pass true to
setBackingStoreEnabled() to use an off-screen image
to increase the efficiency of small scrolls.
JViewport is used by
JScrollPane, and most applications use
JScrollPane instead of using
JViewport directly.

This class is the Swing analog of the
java.awt.Window class. It is a basic heavyweight
top-level window with no titlebar or other frame decorations. Most
applications use JFrame and
JDialog in preference to
JWindow.
Like JFrame and JDialog,
JWindow is a RootPaneContainer,
which means that it has an automatically created
JRootPane as its single child. You are not allowed
to add children or set a layout manager on the
JWindow itself. Instead, you must use the
container returned by the getContentPane().

This class represents a single keystroke, specified either as a character
or, more flexibly, as a keycode plus a set of keyboard modifiers.
KeyStroke objects are immutable, and the
KeyStroke class maintains a cache of the objects.
There is no public KeyStroke constructor.
Instead, call one of the static getKeyStroke()
methods to obtain a reference to a KeyStroke object
that represents the desired keystroke. Note that some versions of
getKeyStroke() take a boolean
argument that
specifies whether the KeyStroke represents a key
release event instead of a key press event.
The keyCode argument
to getKeyStroke() should be
one of the VK_ virtual key constants defined by
java.awt.event.KeyEvent. The
modifiers argument
should be a bitmask composed of the ALT_MASK,
CTRL_MASK, META_MASK, and
SHIFT_MASK constants defined by
java.awt.Event.

See also the registerKeyboardAction() method of
JComponent, the setAccelerator()
method of JMenuItem, and
javax.awt.swing.text.Keymap.

This interface defines the method that must be implemented by any
object that wants to be able to render items in a
JList component. Most applications can rely on the
default behavior of JList (to use a
DefaultListCellRenderer) and never need to
implement or use this interface.
getListCellRendererComponent() is passed
information about the list item that is to be rendered; it should
return a lightweight java.awt.Component capable of
rendering the list item. The JList object
first positions this component at the desired location by calling its
setBounds() method and then asks the component to
draw itself by calling paint(). Note, however,
that the component is never actually added to the component
hierarchy.

This interface defines the methods that must be implemented by any
object that wants to maintain a list of values for display in a
JList or similar component. A
ListModel must be able to return the size of the
list, return any numbered element of the list, and
fire a ListDataEvent event to any registered
ListDataListener objects whenever the contents of the
list changes. ListModel implementations that
represent immutable lists can provide dummy no-op implementations of
the event registration methods.
Most applications do not need to implement this interface; they can
work with JList directly or use the
DefaultListModel class.

This interface defines the methods that an object must implement if it
wants to keep track of the selection state for a
JList, JTable, or similar
component. Most applications use
DefaultListSelectionModel and never have to
implement this interface.

This abstract class defines the methods that a pluggable look-and-feel
must implement. It also defines some useful static convenience methods.
Application programmers should never have to use or subclass this class.
If you are implementing a look-and-feel, you have to
subclass this class and define
the abstract methods, of course. You probably also want to
override the default no-op initialize() and
getDefaults() methods. Finally, you have to provide
implementations of all the abstract classes in
javax.swing.plaf.

This interface defines methods that all menu components must
implement. The methods allow menu navigation and event handling to be
performed in a standard way. Application programmers should never
have to implement this interface or use the methods it defines, unless
they want to place components other than JMenuItem
and its subclasses into menus. See also
MenuSelectionManager.

This class defines methods that manipulate hierarchies of menus.
Application programmers do not need to use this class. There is only
one instance of MenuSelectionManager, returned by
the static defaultManager() method. Menu items
rely on MenuSelectionManager for
implementations of MenuElement methods, and
MenuSelectionManager relies on the methods of the
MenuElement interface to allow it to traverse menu
hierarchies.

This layout manager arranges the children of the container it manages
so that the alignment points (specified with the
setAlignmentX() and
setAlignmentY() methods of
JComponent) are on top of each other. This usually
means that the children overlap. AbstractButton
relies on this layout manager, but applications rarely use it.

This class implements a progress monitor. After creating a
ProgressMonitor, a program periodically calls
setProgress() to indicate its progress toward the
completion of a task. Unless progress is quite rapid, the
ProgressMonitor displays a dialog box that uses
a JProgressBar to display progress to the user.
Call setNote() to set the text to display in the
dialog box. You can also specify a permanent title or heading for the
dialog box with the second argument to the constructor.
The ProgressMonitor dialog box automatically closes
when the progress property reaches the value of the
maximum property. If you want to close it before
the task completes, call close().

ProgressMonitor suffers from an important flaw: if
the user clicks the Cancel buttons in
the dialog box, the dialog is dismissed. Unfortunately, the dialog does not
fire any event to indicate that this has happened, so your program
must call isCancelled() each time it calls
setProgress(), to determine whether the user has
requested that the operation be cancelled. A related flaw is that the
dialog box contains an extraneous Okay
button that behaves just like the Cancel button.

This class combines a java.io.InputStream
with a ProgressMonitor to display a program's
progress in reading a stream. It is useful when reading a long file
or when doing time-consuming processing on data from a shorter
file. If the user clicks the Cancel
button in the dialog, the next call to read data from the stream
results in an InterruptedIOException.
A ProgressMonitorInputStream can only be wrapped
around a stream whose available() method returns
the total remaining number of bytes in the stream,
such as a java.io.FileInputStream. It does not work with
java.io.PipedInputStream, for example.

This interface defines the basic methods that must be implemented
by any class that wants to render a value of some specified type on
behalf of a general-purpose component, such as a
JList. In practice, the
setValue() method defined by this interface is
under-constrained, and this interface is unused in the Swing API.
Three interfaces, with more specialized methods, are used in its
place: ListCellRenderer,
javax.swing.table.TableCellRenderer and
javax.swing.tree.TreeCellRenderer.

public abstract interface Renderer {

//

Public Instance Methods

public abstract Component getComponent ();

public abstract void setValue (Object aValue, boolean isSelected);

}

RepaintManager

Java 1.2

javax.swing

This class manages the repaint and relayout process for all Swing
components in an application. It also provides a shared off-screen
image for Swing components that perform double-buffering.
RepaintManager is an integral part of the Swing GUI
framework and is used extensively by JComponent
internals. Applications rarely need to use it directly. If yours
does, you can obtain the current RepaintManager
with the static currentManager() method.

This interface is implemented by all Swing window and applet
classes that have a JRootPane as their single
child. It defines getRootPane() to return that
JRootPane. It also defines other methods to
return the various children of the JRootPane.
getContentPane() is the most frequently used method
of this interface: it returns the container to which children are
added.

public abstract interface RootPaneContainer {

//

Property Accessor Methods (by property name)

public abstract Container getContentPane ();

public abstract void setContentPane (Container contentPane);

public abstract Component getGlassPane ();

public abstract void setGlassPane (Component glassPane);

public abstract JLayeredPane getLayeredPane ();

public abstract void setLayeredPane (JLayeredPane layeredPane);

public abstract JRootPane getRootPane ();

}

Implementations: JApplet, JDialog, JFrame, JInternalFrame, JWindow

Scrollable

Java 1.2

javax.swing

This interface defines methods that should be implemented by any
component that is likely to be placed within a
JScrollPane or similar scrolling container. A
JScrollPane can provide more intelligent scrolling
services for a Scrollable component than
for a non-Scrollable component.

This interface defines constants used by
JScrollPane and
ScrollPaneLayout. The int
constants are the most interesting ones. They are the legal values
for the setHorizontalScrollBarPolicy() and
setVerticalScrollBarPolicy() methods of
JScrollPane.

public abstract interface ScrollPaneConstants {

//

Public Constants

public static final String COLUMN_HEADER ;

="COLUMN_HEADER"

public static final String HORIZONTAL_SCROLLBAR ;

="HORIZONTAL_SCROLLBAR"

public static final int HORIZONTAL_SCROLLBAR_ALWAYS ;

=32

public static final int HORIZONTAL_SCROLLBAR_AS_NEEDED ;

=30

public static final int HORIZONTAL_SCROLLBAR_NEVER ;

=31

public static final String HORIZONTAL_SCROLLBAR_POLICY ;

="HORIZONTAL_SCROLLBAR_POLICY"

public static final String LOWER_LEFT_CORNER ;

="LOWER_LEFT_CORNER"

public static final String LOWER_RIGHT_CORNER ;

="LOWER_RIGHT_CORNER"

public static final String ROW_HEADER ;

="ROW_HEADER"

public static final String UPPER_LEFT_CORNER ;

="UPPER_LEFT_CORNER"

public static final String UPPER_RIGHT_CORNER ;

="UPPER_RIGHT_CORNER"

public static final String VERTICAL_SCROLLBAR ;

="VERTICAL_SCROLLBAR"

public static final int VERTICAL_SCROLLBAR_ALWAYS ;

=22

public static final int VERTICAL_SCROLLBAR_AS_NEEDED ;

=20

public static final int VERTICAL_SCROLLBAR_NEVER ;

=21

public static final String VERTICAL_SCROLLBAR_POLICY ;

="VERTICAL_SCROLLBAR_POLICY"

public static final String VIEWPORT ;

="VIEWPORT"

}

Implementations: JScrollPane, ScrollPaneLayout

ScrollPaneLayout

Java 1.2

javax.swing

serializable layout manager

This class is the layout manager used by
JScrollPane. It arranges up to nine components: the
JViewport that contains the component being
scrolled, the horizontal and vertical scrollbars, the column and row
header components, and up to four small corner components.
Applications typically use JScrollPane directly
and do not have to use this class.

This interface defines the methods that must be implemented by a
class that wants to keep track of a single selected item for a
JTabbedPane, JMenuBar,
JPopupMenu, or similar component. Applications do
not often implement this interface. Instead, they rely on the
DefaultSingleSelectionModel class, which is the
default model for components that allow a single selected item.

This class exists for the convenience of layout managers. It is used
internally by BoxLayout and
OverlayLayout. Application programmers should not
need to use it. Component developers writing custom layout managers
may find it useful.

This class defines a variety of static methods that are useful in
Swing applications. Highlights include:

invokeLater(), invokeAndWait()

Place the specified Runnable object on the
event queue, so that its run() method is
invoked (later) from the event dispatch thread.
invokeLater() returns immediately;
invokeAndWait() blocks until the
run() method has run. Since Swing is not
generally thread safe, these methods are useful when you need
to update the GUI from a thread that is not the event dispatch
thread.

isEventDispatchThread()

Determines whether the current thread is the event dispatch
thread.

updateComponentTreeUI()

Traverses the entire component tree rooted at the
specified component and asks each component to update its UI
delegate. This method is useful after you have changed the pluggable
look-and-feel of a running application.

isLeftMouseButton(), isMiddleMouseButton(), isRightMouseButton()

Determine whether a
specified MouseEvent involves the left,
middle, or right mouse button. For portability reasons, this
information is encoded in the modifiers
property that the MouseEvent
inherits. These methods simplify
access to it.

getAncestorOfClass()

Given a component and a component class, this method searches
the ancestors of the component until it finds one of the
specified class. getRoot(),
getRootPane(),
windowForComponent(), and
getAncestorNamed() are related methods.

This utility class fires an ActionEvent
to a list of registered ActionListener objects after a
specified period of time has elapsed. Optionally, it may continue to
fire action events at specified time intervals. This class is
useful for triggering delayed or repeated actions, such as
animations.
After creating a Timer object, adding one or
more ActionListener objects, and setting any
necessary properties, call start() to make the
Timer object start timing and firing events. If
you have configured the Timer to fire events
repeatedly, use the stop() method when you want the
events to stop.

The initialDelay property specifies the time in
milliseconds between the invocation of the start()
method and the firing of the first ActionEvent.
The repeats property specifies whether the
Timer fires events repeatedly.
If repeats is
true, the delay property
specifies the interval (in milliseconds) between repeated events. If
the delay property is set to a short interval or
if the ActionEvent triggers a complex action,
the Timer may sometimes get behind and develop a
backlog of events. Set the coalesce property to
true if the Timer is allowed to
coalesce multiple pending events into a single
ActionEvent in this situation. The
Timer constructor sets the
repeats and coalesce properties to
true, so be sure to change these properties if
you don't want that behavior. The constructor also
sets both the delay
and initialDelay properties to the specified
interval.
The static setLogTimers() method is useful when
debugging code that uses the Timer class. Passing
true to this method causes Timer
to print a debugging message to standard output each time it fires an
event.

This class manages tooltips for a Swing application. There is only
one ToolTipManager per application; you can obtain
a reference to it with the static sharedInstance()
method.
Any Swing component that has a tooltip set on it (with
setToolTipText()) is automatically registered with
the ToolTipManager, so applications do not usually
have to work with this class explicitly. If you want to
explicitly register or unregister a component without setting its
tooltip text, you can do so with
registerComponent() and
unregisterComponent(), respectively.

To disable all tooltips in an application (at the request of
an advanced user, for example), set the enabled
property to false. The other
ToolTipManager properties are various delays that
affect the behavior of tooltips. These values are user preferences,
and an application should not modify them except in response to an
explicit user request made through some kind of preferences dialog or
control panel.

UIDefaults is a Hashtable
subclass used to maintain a table of named resources for use by a
look-and-feel implementation. Like any hashtable,
UIDefaults defines a get() and a
put() method. In addition, it defines numerous
more specific
getXXX() methods
that are used to
look up resources of specific types.
Unless you are defining a custom look-and-feel, you probably do not
have to use this class explicitly.

The generic get() method and all the more specific
methods that use it have a special
behavior if the returned resource value implements either of the inner
interfaces defined by UIDefaults. If the returned
object is a UIDefaults.ActiveValue, the
value returned by the get() method is computed by
calling the createValue() method of the
ActiveValue object. Similarly, if the returned
value is a LazyValue, the final return value
of the get() method is computed by calling the
createValue() method of the
LazyValue object. Once this computation is done
the first time, however, the LazyValue is replaced
in the UIDefaults table with the computed value it
yielded. This is a useful technique for resources such as icons that
have to be read in from external files. It prevents them from being
created unless they are actually needed.

This interface defines a special kind of resource that can be stored
in a UIDefaults hashtable. When the
get() method of UIDefaults finds
a ActiveValue in the table, it does not return the
ActiveValue object. Instead, it invokes its
createValue() method and returns the object
returned by that method.

public abstract static interface UIDefaults.ActiveValue {

//

Public Instance Methods

public abstract Object createValue (UIDefaults table);

}

UIDefaults.LazyValue

Java 1.2

javax.swing

This interface defines a special kind of resource that can be stored
in a UIDefaults hashtable. When the
get() method of UIDefaults finds
an LazyValue in the table, it does not return the
LazyValue object. Instead, it invokes its
createValue() method. The object returned by
createValue() is used to replace the
LazyValue in the
UIDefaults table and is then returned by the
get() method.

public abstract static interface UIDefaults.LazyValue {

//

Public Instance Methods

public abstract Object createValue (UIDefaults table);

}

UIManager

Java 1.2

javax.swing

serializable

The static methods of this class perform a number of
look-and-feel related functions. setLookAndFeel()
is the most important. It takes a LookAndFeel
object or the class name of the desired look-and-feel and makes it
the current look-and-feel. getLookAndFeel()
returns the LookAndFeel object that represents the
current look-and-feel.
getCrossPlatformLookAndFeelClassName() and
getSystemLookAndFeelClassName() return class names
for the default Java look-and-feel and for the look-and-feel that
mimics the native platform look-and-feel, if one exists.
getInstalledLookAndFeels() returns information
about all look-and-feels that are installed on the system.

The UIManager also manages user interface defaults
specified both by the current look-and-feel and by the application.
The get() method looks up a value for the named
key, checking the table of application defaults first and then
checking the defaults specified by the look-and-feel. The
put() method inserts a new key/value binding into
the application defaults table; it does not modify the look-and-feel
defaults. UIManager defines various other
type-specific
getXXX() methods
that can be used to
look up default UI resources of various types.

Although all the methods of UIManager are static,
they are implemented in such a way that each separate application
context can independently set its own look-and-feel defaults.
This means, for example, that multiple applets running in the same
Java VM can install and use different look-and-feel implementations.

Instances of this class are returned by the
getInstalledLookAndFeels() method of
UIManager. The getName() method
of each LookAndFeelInfo provides a simple
human-presentable name that can be displayed to the user in a list or
menu that allows the user to choose a look-and-feel.