Java Reference
In-Depth Information
In a larger GUI example, an event listener might examine the text that is written in
a text area by calling its
getText
method or set new text in the text area by calling its
setText
method.
Currently, when the user types too much text to fit in the text area, the text disap-
pears off the bottom of the text box:
To fix this problem, we can make the text area scrollable by adding familiar navi-
gation components called
scrollbars
to it. Scrollbars are represented by instances of a
special container component called a
JScrollPane
. To make a component scrolla-
ble, create a
JScrollPane
, add the component to the scroll pane, and then add the
scroll pane to the overall frame. You construct a
JScrollPane
object by passing the
relevant component as a parameter:
// use scrollbars on this text area
frame.add(new JScrollPane(area));
We add the
JScrollPane
instead of the
JTextArea
to the frame, and the scroll
pane creates scrollbars along the right and bottom edges of the text area when the text
that the user enters is too large to display:
The appearance of onscreen text is determined by
fonts,
which are sets of descrip-
tions for how to display text characters. If you don't like the default font of the text
area, remember that every component has a font property that you can set. As we
Search WWH ::
Custom Search