Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java - JList remove with double click

  • 22-07-2013 1:14pm
    #1
    Closed Accounts Posts: 446 ✭✭


    Hi, Trying to teach myself Java over the summer and was going well until I ran into this little problem. I have a Jlist and want to remove an Item when I double click it.

    I see MouseListener doesnt have a method to deal with double click so I tried to make my own one in an inner class that extends the MouseAdapter class so I can use the getClickCount() method but for some reason nothing is happening, not even showing errors. Can anybody tell me why/ point me in the right direction?
    public class RemoveSelectedItem extends MouseAdapter {
     
      public void mouseClicked(MouseEvent ev){
           JList list = (JList)ev.getSource();
           DefaultListModel listModel = (DefaultListModel)list.getModel();
     
               if (ev.getClickCount() == 2) {
                  listModel.remove(list.getSelectedIndex());
               } 
     
     
       }
     
     
     }
    


Comments

Advertisement