Scroll Panes

A ScrollPane can be used to make other components scrollable. ScrollPanes should be used to contain components that are bigger than their allocated screen space. In the example below, a ScrollPane has been placed around a TextArea.

TextArea_Scrollable_Demo example: (Run Applet)

import java.awt.*;
import javax.swing.*;

public class TextArea_Scrollable_Demo extends JApplet
{
    @Override
    public void init()
    {
        this.setContentPane(new View());
    }

    public class View extends JPanel
    {
        public View()
        {
            final JTextArea textArea = new JTextArea();
            final JScrollPane scrollPane = new JScrollPane(textArea); // make area1 scrollable

            this.setLayout(new GridLayout(1, 1));

            this.add(scrollPane); // add the scrollable area

            textArea.append("When there is too much text to be display in the JTextArea, the JScrollPane automatically produces scroll bars.");
        }
    }
}

What other components could be usefully placed inside a ScrollPane? Explain why ScrollPanes would be useful in these cases.

 
<div align="center"><a href="../versionC/index.html" title="DKIT Lecture notes homepage for Derek O&#39; Reilly, Dundalk Institute of Technology (DKIT), Dundalk, County Louth, Ireland. Copyright Derek O&#39; Reilly, DKIT." target="_parent" style='font-size:0;color:white;background-color:white'>&nbsp;</a></div>