Scroll Panes

Components in a GUI are often bigger than the area available to display them. To move from one part of the component to another, vertical and horizontal scrollbars are used.

In Swing, you offer scrolling by adding a component to a scroll pane, a container that is represented by the JScrollPane class.

You can create a scroll pane with the following constructors:

JScrollPane()—Create a scroll pane with a horizontal and vertical scrollbar that appear as needed.

JScrollPane(int, int)— Create a scroll pane with the specified vertical scrollbar and horizontal scrollbars.

JScrollPane(Component)—Create a scroll pane that contains the specified user interface component.

JScrollPane(Component, int, int)—Create a scroll pane with the ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition 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.