import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
public class SimpleList extends JFrame {
protected JList list;
public SimpleList() {
super("Simple Swing List");
setSize(500, 240);
String[] item = { "First", "Second", "Third" };
list = new JList(item);
JScrollPane scrollPane = new JScrollPane();
scrollPane.getViewport().add(list);
getContentPane().add(scrollPane, BorderLayout.CENTER);
WindowListener exit = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
addWindowListener(exit);
setVisible(true);
}
public static void main(String argv[]) {
new SimpleList();
}
}
|