Java Reference
In-Depth Information
Configuring
JButton
buttons[1]
JButton
buttons[1]
(lines 52-53) has
weightx
and
weighty
values of 1. The
fill
vari-
able is
BOTH
. Line 52 specifies that the
JButton
is to be placed relative to the previous com-
ponent. The
Button
is added to the
JFrame
with a call to
addComponent
.
Configuring
JButton
buttons[2]
JButton
buttons[2]
(lines 56-57) has
weightx
and
weighty
values of 1. The
fill
vari-
able is
BOTH
. This
JButton
is the last component on the line, so
REMAINDER
is used. The
JButton
is added to the content pane with a call to
addComponent
.
Configuring
JComboBox
The
JComboBox
(lines 60-62) has a
weightx
of 1 and a
weighty
of 0. The
JComboBox
will
not grow vertically. The
JComboBox
is the only component on the line, so
REMAINDER
is
used. The
JComboBox
is added to the content pane with a call to
addComponent
.
Configuring
JButton
buttons[3]
JButton
buttons[3]
(lines 65-67) has
weightx
and
weighty
values of 1. The
fill
vari-
able is
BOTH
. This
JButton
is the only component on the line, so
REMAINDER
is used. The
JButton
is added to the content pane with a call to
addComponent
.
Configuring
JButton
buttons[4]
JButton
buttons[4]
(lines 70-71) has
weightx
and
weighty
values of 1. The
fill
vari-
able is
BOTH
. This
JButton
is the next-to-last component on the line, so
RELATIVE
is used.
The
JButton
is added to the content pane with a call to
addComponent
.
Configuring
JList
The
JList
(lines 74-75) has
weightx
and
weighty
values of 1. The
fill
variable is
BOTH
.
The
JList
is added to the content pane with a call to
addComponent
.
This chapter completes our introduction to GUIs. In this chapter, we discussed additional
GUI topics, such as menus, sliders, pop-up menus, multiple-document interfaces, tabbed
panes and Java's pluggable look-and-feel. All these components can be added to existing
applications to make them easier to use and understand. We also presented additional lay-
out managers for organizing and sizing GUI components. In the next chapter, you'll learn
about multithreading, which allows you to specify that an application should perform
multiple tasks at once.
Summary
Section 22.2
JSlider
•
JSlider
s (p. 912) enable you to select from a range of integer values. They can display major and
minor tick marks, and labels for the tick marks (p. 912). They also support snap-to ticks (p. 912)
—
positioning the thumb (p. 912) between two tick marks snaps it to the closest tick mark.
•
JSlider
s have either horizontal or vertical orientation. For a horizontal
JSlider
, the minimum
value is at the extreme left and the maximum value at the extreme right. For a vertical
JSlider
,