Chapter 31. The JList Class
The JList class is a more powerful replacement for the AWT's List class. A JList can be instantiated using a Vector or an array to represent its contents. It does not support scrolling and thus must be added to a JScrollPane to allow scrolling to take place.
In the simplest program that you can write using a JList, you
add a JScrollPane to the Frame,
create a Vector of data,
create a JList using the Vector, and
add the JList to the JScrollPane's viewport.
This program is shown next.
JPanel jp = new JPanel(); //a panel in Frame getContentPane().add(jp); //create a scroll pane JScrollPane sp = new JScrollPane(); jp.add(sp); //add the pane to the layout Vector dlist = new Vector(); //create a Vector dlist.addElement("Anchovies"); ...