JScrollPane Class

Package: javax.swing

The JScrollPane class creates scroll bars, which you use in conjunction with other controls such as text areas or list controls.

Note: This section doesn’t list any methods for the JScrollPane class. The JScrollPane class does have methods (plenty of them, in fact), but none of them are particularly useful for ordinary programming.

Constructors

Constructor

Description

JScrollPane(Component view)

Creates a scroll pane for the specified component

JScrollPane(Component, int vert, int hor)

Creates a scroll pane for the specified component with the specified policy for the vertical and horizontal scroll bars

Fields

Field

Description

VERTICAL_SCROLLBAR_ALWAYS

Always adds a vertical scroll bar

VERTICAL_SCROLLBAR_AS_NEEDED

Adds a vertical scroll bar if necessary

VERTICAL_SCROLLBAR_NEVER

Never adds a vertical scroll bar

HORIZONTAL_SCROLLBAR_ALWAYS

Always adds a horizontal scroll bar

HORIZONTAL_SCROLLBAR_AS_NEEDED

Adds a horizontal scroll bar if necessary

HORIZONTAL_SCROLLBAR_NEVER

Never adds a horizontal scroll bar

The usual way to create a scroll pane is to use the second constructor. You use the first parameter of this constructor to specify the component to which you want to add scroll bars. To add scroll bars to a text area named MyTextArea, for example, you specify MyTextArea as the first parameter.

The second parameter tells the scroll pane whether to create a vertical ...

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.