ptg7068951
222 HOUR 16:Building a Complex User Interface
The text of an email is entered in a scrolling text area, which is implement-
ed by creating a text area and adding it to a scroll pane with the following
statements:
JTextArea message = new JTextArea(4, 22);
message.setLineWrap(true);
message.setWrapStyleWord(true);
JScrollPane scroll = new JScrollPane(message,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
row3.add(scroll);
Sliders
The easiest way to collect numeric input from a user is with a slider, a com-
ponent that can be dragged from side to side or up and down. Sliders are
represented in Swing by the JSliderclass.
Sliders enable a number to be chosen between minimum and maximum
values. These values can be displayed on a label that includes the mini-
mum value, maximum value, and intermediate values. An example you
create later is shown in Figure 16.2.
You can create a horizontal slider with one of the following constructors:
. JSlider()—Create a slider with a minimum of 0, maximum of 100,
and starting value of 50.
. JSlider(int, int)—Create a slider with the specified minimum
and maximum values.
. JSlider(int, int, int)—Create a slider with the specified mini-
mum, maximum, and starting values.
FIGURE 16.1
Displaying a scrollingtext area in
an application.
FIGURE 16.2
Choosing a color using three slider
components.