The JScrollPane Class

The JScrollPane class offers a more flexible version of the ScrollPane class found in the AWT package. Beyond the automatic scrollbars, you can put in horizontal and vertical headers as well as active components in the corners of your pane.
Many Swing components use JScrollPane to handle their scrolling. The JList component, for example, does not handle scrolling on its own. Instead, it concentrates on presenting the list and making selection easy, assuming you’ll put it inside a JScrollPane if you need scrolling.

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

public class ScrollList extends JFrame {

	JScrollPane scrollpane;

	public ScrollList() {
		super("JScrollPane Demonstration");
		setSize(300, 200);

		String categories[] = { "Household", "Office", "Extended Family", 
                                        "Company (US)", "Company (World)", 
                                        "Team","Will", "Birthday Card List", 
                                        "High School", "Country", "Continent", 
                                        "Planet" };
		JList list = new JList(categories);
		scrollpane = new JScrollPane(list);

		getContentPane().add(scrollpane, BorderLayout.CENTER);

	public static void main(String args[]) {
		ScrollList sl = new ScrollList();