Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
This chapter discusses the Swing scrolling architecture, which includes two lightweight Swing containers—JViewport and JScrollPane—a Scrollable interface designed to support components with special scrolling needs and a JScrollBar class.
Instances of JViewport are rarely instantiated and used directly; however, a considerable portion of this chapter is dedicated to the JViewport class because it is the fundamental component in the Swing scrolling architecture.
The JScrollPane component is designed to replace the AWT's heavyweight ScrollPane component. JScrollPane offers many improvements over the AWT's ScrollPane, including the ability to attach row and column headers and, in addition to specifying components that reside in the corners of the scrollpane.[In this chapter, scrollpane is one word. OK, but then change it on pages 11 and 54.]
The Scrollable interface is designed for scrollable components that contain rows or columns of data such as tables, trees, text components, and lists.
The JScrollBar component is a scrollbar that can be used to implement manual scrolling. Although Swing's JScrollPane component is sufficient for most scrolling situations, there are times when scrolling must be implemented manually for due to performance or resource considerations. In such cases, the JScrollBar component can be used to scroll the contents of a container.