Java Reference
In-Depth Information
This is one of many situations in Swing where you must do some-
thing in the proper order for it to work correctly. For most compo-
nents, the order is the following: Create the component, set up
the component fully, and then add the component to a container.
CAUTION
By default, a scroll pane does not display scrollbars unless they are needed. If the com-
ponent inside the pane is no larger than the pane itself, the bars won't appear. In the case
of components such as text areas, where the component size might increase as the pro-
gram is used, the bars automatically appear when they're needed and disappear when
they are not.
To override this behavior, you can set a policy for a JScrollBar component when you
create it. You set the policy by using one of several ScrollPaneConstants class con-
stants:
HORIZONTAL_SCROLLBAR_ALWAYS
n
HORIZONTAL_SCROLLBAR_AS_NEEDED
n
HORIZONTAL_SCROLLBAR_NEVER
n
VERTICAL_SCROLLBAR_ALWAYS
n
VERTICAL_SCROLLBAR_AS_NEEDED
n
VERTICAL_SCROLLBAR_NEVER
n
These class constants are used with the JScrollPane( Object , int , int ) constructor,
which specifies the component in the pane, the vertical scrollbar policy, and the horizon-
tal scrollbar policy.
Any Swing component that requires scrolling can be placed within
a scroll pane. If you're scrolling a text area and need to jump to
the bottom of the pane whenever new text is added, call the
text area component's setCaretPosition(getDocument()
.getLength()) method. The argument to setCaretPosition()
indicates how much text the area currently holds.
NOTE
Toolbars
A toolbar , created in Swing with the JToolBar class, is a container that groups several
components into a row or column. These components are most often buttons.
 
Search WWH ::




Custom Search