Java Reference
In-Depth Information
LISTING 9.5
Continued
31: }
32:
33: public static void main(String[] arguments) {
34: Authenticator auth = new Authenticator();
35: }
36: }
Figure 9.4 shows the application in use. The password is obscured with asterisk charac-
ters (“*”), which is the default when no other echo character is designated by calling the
field's setEchoChar( char ) method.
FIGURE 9.4
The
Authenticator
application.
The text area in this application behaves in a manner that you might not expect. When
you reach the bottom of the field and continue entering text, the component grows to
make more room for input. The next section describes how to add scrollbars to prevent
the area from changing in. size.
Scrolling Panes
Text areas in Swing do not include horizontal or vertical scrollbars, and there's no way to
add them using this component alone.
Swing supports scrollbars through a new container that can be used to hold any compo-
nent that can be scrolled: JScrollPane .
A scrolling pane is associated with a component in the pane's constructor. You can use
either of the following constructors:
JScrollPane( Component ) —A scrolling pane that contains the specified
component
n
JScrollPane( Component , int , int ) —A scrolling pane with the specified com-
ponent, vertical scrollbar configuration, and horizontal scrollbar configuration
n
 
Search WWH ::




Custom Search