FileDocCategorySizeDatePackage
SimpleList2.javaAPI DocExample1955Thu Oct 24 20:14:22 BST 2002None

SimpleList2

public class SimpleList2 extends JPanel

Fields Summary
String[]
label
JList
list
Constructors Summary
public SimpleList2()


      
        setLayout(new BorderLayout());

        list = new JList(label);
        JButton button = new JButton("Print");
        JScrollPane pane = new JScrollPane(list);

        DefaultListSelectionModel m = new DefaultListSelectionModel();
        m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        m.setLeadAnchorNotificationEnabled(false);
        list.setSelectionModel(m);

        list.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                System.out.println(e.toString());
            }
        });
        button.addActionListener(new PrintListener());

        add(pane, BorderLayout.NORTH);
        add(button, BorderLayout.SOUTH);
    
Methods Summary
public static voidmain(java.lang.String[] s)

         JFrame frame = new JFrame("List Example");
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.setContentPane(new SimpleList2());
         frame.pack();
         frame.setVisible(true);