The JScrollBar Class

JScrollBar is the Swing implementation of a scrollbar. It is the lightweight successor to the AWT 1.1 counterpart java.awt.Scrollbar, and is intended as a direct replacement for programmers converting their applications to Swing. The JScrollBar class is shown with various look-and-feels in Figure 6.3.

Scrollbars in the three look-and-feels

Figure 6-3. Scrollbars in the three look-and-feels

To program with a scrollbar, it is important to understand its anatomy. Scrollbars are composed of a rectangular tab, called a slider or thumb, located between two arrow buttons. The arrow buttons on either end increment or decrement the slider’s position by an adjustable number of units, generally one. In addition, clicking in the area between the thumb and the end buttons (often called the paging area) moves the slider one block, or ten units by default. The user can modify the value of the scrollbar in one of three ways: by dragging the thumb in either direction, by pushing on either of the arrow buttons, or by clicking in the paging area.

As with AWT, scrollbars can have one of two orientations: horizontal or vertical. Figure 6.4 provides an illustration of a horizontal scrollbar. JScrollBar makes use of the bounded-range model to represent the scrollbar’s data. The assignment of each bounded-range property is also shown in Figure 6.5. The minimum and maximum of the scrollbar fall on the interior edges of the ...

Get Java Swing 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.