FileDocCategorySizeDatePackage
JListDemo.javaAPI DocExample917Sun Jul 13 20:43:42 BST 2003None

JListDemo

public class JListDemo extends JFrame
Demonstrate Swing "JList" ScrollingList.

Fields Summary
JList
list
Constructors Summary
JListDemo(String s)


	  
		super(s);
		Container cp = getContentPane();
		cp.setLayout(new FlowLayout());
		ArrayList data = new ArrayList();
		data.add("Hi");
		data.add("Hello");
		data.add("Goodbye");
		data.add("Adieu");
		data.add("Adios");
		list = new JList(data.toArray());
		list.addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(ListSelectionEvent evt) {
				if (evt.getValueIsAdjusting())
					return;
				System.out.println("Selected from " +
					evt.getFirstIndex() + " to " + evt.getLastIndex());
			}
		});
		cp.add(list, BorderLayout.CENTER);
	
Methods Summary
public static voidmain(java.lang.String[] s)

		JListDemo l = new JListDemo("Greetings");
		l.pack();
		l.setVisible(true);