FileDocCategorySizeDatePackage
SimpleList.javaAPI DocExample1290Mon Nov 09 12:45:54 GMT 1998None

SimpleList

public class SimpleList extends JPanel implements ActionListener

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


      
        this.setLayout(new BorderLayout());
        list = new JList(label);
        JScrollPane pane = new JScrollPane(list);
        JButton button = new JButton("Print");
        button.addActionListener(this);

        add(pane, BorderLayout.NORTH);
        add(button, BorderLayout.SOUTH);
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

        int selected[] = list.getSelectedIndices();
        System.out.println("Selected Elements:  ");

        for (int i=0; i < selected.length; i++) {
            String element =
                  (String)list.getModel().getElementAt(selected[i]);
            System.out.println("  " + element);
        }
    
public static voidmain(java.lang.String[] s)

         JFrame frame = new JFrame("Simple List Example");
         frame.addWindowListener(new BasicWindowMonitor());
         frame.setContentPane(new SimpleList());
         frame.setSize(250, 180);
         frame.setVisible(true);