Creating a List Component The list fires a list selection event whenever its set of selected items changes. // A multiple selection list. String[] items = {"item1", "item2"}; JList list = new JList(items); // The next two lines should be in one line. list.addListSelectionListener( new MyListSelectionListener()); // Make the list single selection mode // The next two lines should be in one line. list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION); // The next two lines should be in one line. class MyListSelectionListener implements ListSelectionListener { // The next two lines should be in one line. public void valueChanged( ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { JList list = (JList)evt.getSource(); // The next two lines should be in one line. Object[] selected = list.getSelectedValues(); for (int i=0; i