Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java - JList remove with double click

  • 22-07-2013 02: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