title: Removing element from JList is not working
body: <p>I have a JList that lists an arrayList. When I press the button called delete I want to delete the selected element from the list (and ideally the arraylist). At the moment I have the following code, however it is not working. By this I mean that it seems to do nothing if an element is selected and it gives me a ArrayIndexOutOfBoundsException when nothing is selected.</p>
  
  <pre><code>private JList listOrders = new JList(arrayList.toArray());
  
  public void myList() {
      listOrders.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION );
      panelForLists.add(listOrders);
  }
  
  public void updateList() {
      listOrders.setListData(arrayList.toArray());
      listOrders.revalidate();
      listOrders.repaint();
  }
  
  public void actionPerformed(ActionEvent event) {
      if (event.getSource() == deleteItem) {
           int index = listOrders.getSelectedIndex();
              listOrders.remove(index);
             updateList();
      }
  }
  </code></pre>
  
  <p>I assume that maybe it's because I have to add in a ListSelectionListener somewhere, but I don't know how I can work this. I've searched on the internet for an answer for ages and this was what I came up with from the JList oracle demo.</p>
  
  <p>Thanks a lot!</p>