Java Reference
In-Depth Information
Frame
Document (text or picture)
Slider
Slidebar
View to document
(viewport)
Area of the document which
is currently visible in the viewport
Figure 11.1 Structure of a scrollable component
Let us augment the application from Section 10.2 so that the text can be scrolled.
Our text is still loaded into a JEditorPane .Wethen generate a scroll pane
to display parts of it. The vertical scroll bar is visible at once. The horizontal
one does not appear even though the text contains a very long line. The rea-
son is that the JEditorPanel breaks long lines when reading them. One has
to first make the panel wide (using the mouse) and then narrow to make the
horizontal scroll bar appear. The functions of the scrollbars are automatically
supplied. Moving the horizontal or vertical slider moves the viewport inside the
document.
In the following we list the code for TextDisplayScrollFrame which dis-
plays scrollable text. The driver class TextDisplayScrollDriver is not listed.
Figure 11.2 shows the result.
Figure 11.2 TextDisplayScrollFrame
Search WWH ::




Custom Search