ptg7068951
Using Components 179
This example creates a single JComboBoxcomponent that provides six
choices from which the user can select. When one is selected, it appears in
the display of the component. Figure 13.5 shows this example while the
pop-up list of choices is being displayed.
FIGURE 13.5
Displaying combo box
components.
To enable a JComboBoxcomponent to receive text input, you must call its
setEditable()method with an argument of true:
profession.setEditable(true);
You must call this method before the component is added to a container.
Text Areas
AJTextAreacomponent is a text field that enables the user to enter more
than one line of text. You can specify the width and height of the compo-
nent. Thefollowing statements create and add a JTextAreacomponent
with a width of 40 characters and a height of 8 lines and to a container:
JTextArea comments = new JTextArea(8, 40);
FlowLayout flo = new FlowLayout();
setLayout(flo);
add(comments);
Figure 13.6 shows this example in a frame.
FIGURE 13.6
Displaying text area components.