Java Reference
In-Depth Information
•
JRadioButton
s are used to represent mutually exclusive options (p. 501).
• The logical relationship between
JRadioButton
s is maintained by a
ButtonGroup
object (p. 501).
•
ButtonGroup
method
add
(p. 504) associates each
JRadioButton
with a
ButtonGroup
. If more
than one selected
JRadioButton
object is added to a group, the selected one that was added first
will be selected when the GUI is displayed.
•
JRadioButton
s generate
ItemEvent
s when they're clicked.
Section 12.11
JComboBox
; Using an Anonymous Inner Class for Event Handling
•A
JComboBox
(p. 504) provides a list of items from which the user can make a single selection.
JComboBox
es generate
ItemEvent
s.
•Each item in a
JComboBox
has an index (p. 507). The first item added to a
JComboBox
appears as
the currently selected item when the
JComboBox
is displayed.
•
JComboBox
method
setMaximumRowCount
(p. 507) sets the maximum number of elements that are
displayed when the user clicks the
JComboBox
.
• An anonymous inner class (p. 507) is a class without a name and typically appears inside a meth-
od declaration. One object of the anonymous inner class must be created when the class is de-
clared.
•
JComboBox
method
getSelectedIndex
(p. 508) returns the index of the selected item.
Section 12.12
JList
•A
JList
displays a series of items from which the user may select one or more items. Class
JList
supports single-selection lists (p. 508) and multiple-selection lists.
• When the user clicks an item in a
JList
, a
ListSelectionEvent
(p. 508) occurs.
JList
method
addListSelectionListener
(p. 510) registers a
ListSelectionListener
(p. 510) for a
JList
's
selection events. A
ListSelectionListener
of package
javax.swing.event(
p. 492) must imple-
ment method
valueChanged
.
•
JList
method
setVisibleRowCount
(p. 510) specifies the number of visible items in the list.
•
JList
method
setSelectionMode
(p. 510) specifies a list's selection mode.
•A
JList
can be attached to a
JScrollPane
(p. 510) to provide a scrollbar for the
JList
.
•
JFrame
method
getContentPane
(p. 510) returns a reference to the
JFrame
's content pane where
GUI components are displayed.
•
JList
method
getSelectedIndex
(p. 511) returns the selected item's index.
Section 12.13 Multiple-Selection Lists
• A multiple-selection list (p. 511) enables the user to select many items from a
JList
.
•
JList
method
setFixedCellWidth
(p. 513) sets a
JList
's width.
M
ethod
setFixedCellHeight
(p. 513) sets the height of each item in a
JList
.
• Normally, an external event (p. 513) generated by another GUI component (such as a
JButton
)
specifies when the multiple selections in a
JList
should be processed.
•
JList
method
setListData
(p. 513) sets the items displayed in a
JList
.
JList
method
getSe-
lectedValues
(p. 513) returns an array of
Object
s representing the selected items in a
JList
.
Section 12.14 Mouse Event Handling
•The
MouseListener
(p. 513) and
MouseMotionListener
(p. 513) event-listener interfaces are
used to handle mouse events (p. 513). Mouse events can be trapped for any GUI component that
extends
Component
.