Java Reference
In-Depth Information
Scrollbars are configured using static class variables of the ScrollPaneConstants inter-
face. You can use each of the following for vertical scrollbars:
n
VERTICAL_SCROLLBAR_ALWAYS
n
VERTICAL_SCROLLBAR_AS_NEEDED
n
VERTICAL_SCROLLBAR_NEVER
There also are three similarly named variables for horizontal scrollbars.
After you create a scrolling pane containing a component, the pane should be added to
containers in place of that component.
9
The following example creates a text area with a vertical scrollbar and no horizontal
scrollbar and then adds it to a content pane:
JPanel pane = new JPanel();
JTextArea comments = new JTextArea(4, 15);
JScrollPane scroll = new JScrollPane(comments,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pane.add(scroll);
setContentPane(pane);
A full application that makes use of this code, Authenticator2, can
be viewed on this topic's website. Visit http://www.java21days.
com and open the Day 9 page. Look for the link to Authenticator2.
java .
NOTE
Check Boxes and Radio Buttons
The next two components you will learn about, check boxes and radio buttons, hold only
two possible values: selected or not selected.
Check boxes are used to make a simple choice in an interface, such as yes-no or on-off.
Radio buttons are grouped together so that only one button can be selected at any time.
Check boxes (the JCheckBox class) appear as labeled or unlabeled boxes that contain a
check mark when they are selected and nothing otherwise. Radio buttons (the
JRadioButton class) appear as circles that contain a dot when selected and are also
empty otherwise.
Search WWH ::




Custom Search