Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com

Crux.

A javax.swing.JScrollPane is used .

A custom component is used that doesn't do much more than draw itself.

An instance of it is created first...

and the reference to it passed as argument to the JScrollPane constructor.

Our custom component is larger than the scrollpane, so we have to scroll to see all of it.

It draws itself according to the amount scrolled, so you can see that JScrollPane is very useful, indeed. JScrollPane is a Container, so it can contain any Component !, even another Container. It is often used for a JTextArea or JList .

So, for the contained component to be drawn accurately, you don't have to do anything. If, however, you need to know the amount scrolled,...

you can use this technique.

Clicking the pane's vertical 'arrows' shifts the view by 5 pixels. Horizontal arrows shift by one, default.

======

NOTE

======

Could draw a java.awt.Image here.

.