Java Reference
In-Depth Information
the minimum value is at the extreme bottom and the maximum value at the extreme top. The
position of the thumb indicates the current value of the
JSlider
. Method
getValue
(p. 916) of
class
JSlider
returns the current thumb position.
•
JSlider
method
setMajorTickSpacing
() sets the spacing for tick marks on a
JSlider
. Method
setPaintTicks
(p. 916) with a
true
argument indicates that the tick marks should be displayed.
•
JSlider
s generate
ChangeEvents
when the user interacts with a
JSlider
. A
ChangeListener
(p. 916) declares method
stateChanged
(p. 916) that can respond to
ChangeEvent
s.
Section 22.3 Understanding Windows in Java
• A window's (p. 916) events can be handled by a
WindowListener
(p. 917), which provides seven
window-event-handling methods—
windowActivated
,
windowClosed
,
windowClosing
,
window-
Deactivated
,
windowDeiconified
,
windowIconified
and
windowOpened
.
Section 22.4 Using Menus with Frames
• Menus neatly organize commands in a GUI. In Swing GUIs, menus can be attached only to ob-
jects of classes with method
setJMenuBar
(p. 917).
•A
JMenuBar
(p. 917) is a container for menus. A
JMenuItem
appears in a menu. A
JMenu
(p. 917)
contains menu items and can be added to a
JMenuBar
or to other
JMenu
s as submenus.
• When a menu is clicked, it expands to show its list of menu items.
•When a
JCheckBoxMenuItem
(p. 918) is selected, a check appears to the left of the menu item.
When the
JCheckBoxMenuItem
is selected again, the check is removed.
•In a
ButtonGroup
, only one
JRadioButtonMenuItem
(p. 918) can be selected at a time.
•
AbstractButton
method
setMnemonic
(p. 923) specifies the mnemonic (p. 918) for a button.
Mnemonic characters are normally displayed with an underline.
• A modal dialog box (p. 923) does not allow access to any other window in the application until
the dialog is dismissed. The dialogs displayed with class
JOptionPane
are modal dialogs. Class
JDialog
(p. 923) can be used to create your own modal or nonmodal dialogs.
Section 22.5
JPopupMenu
• Context-sensitive pop-up menus (p. 925) are created with class
JPopupMenu
. The pop-up trigger
event occurs normally when the user presses and releases the right mouse button.
MouseEvent
method
isPopupTrigger
(p. 928) returns
true
if the pop-up trigger event occurred.
•
JPopupMenu
method
show
(p. 928) displays a
JPopupMenu
. The first argument specifies the origin
component
,
which helps determine where the
JPopupMenu
will appear. The last two arguments are
the coordinates from the origin component's upper-left corner, at which the
JPopupMenu
appears.
Section 22.6 Pluggable Look-and-Feel
• Class
UIManager.LookAndFeelInfo
(p. 929) maintains information about a look-and-feel.
•
UIManager
(p. 929)
static
method
getInstalledLookAndFeels
(p. 929) returns an array of
UIManager.LookAndFeelInfo
objects that describe the available look-and-feels.
•
UIManager
static
method
setLookAndFeel
(p. 932) changes the look-and-feel.
SwingUtilities
(p. 932)
static
method
updateComponentTreeUI
(p. 932) changes the look-and-feel of every
component attached to its
Component
argument to the new look-and-feel.
Section 22.7
JDesktopPane
and
JInternalFrame
• Many of today's applications use a multiple-document interface (MDI; p. 933) to manage sev-
eral open documents that are being processed in parallel. Swing's
JDesktopPane
(p. 933) and
JInternalFrame
(p. 933) classes provide support for creating multiple-document interfaces.