Home Segments Top Top Previous Next

857: Mainline

If you have more than a few movies, you will want to view those movies in a choice list with a scroll bar. Using Java, you add a scroll bar to a choice list by viewing the choice list through a scroll pane, which automatically adds vertical or horizontal scroll bars, as needed. This addition requires just a small flourish: You create a scroll pane, an instance of the JScrollPane class, with the choice list as its argument. Then, instead of adding the choice list to the applet's content pane, you add the scroll pane.

getContentPane().add("East", getJList()); 
                              | 
                              | Replaced by 
                              v 
getContentPane().add("East", new JScrollPane(getJList())); 

Testing the applet with the scroll pane installed produces the display shown in Segment 848.