0

I have two events that support the button and table by click mouse if i click te button should remove the record from the list and table. It happens but program display this exception ArrayIndexOutOfBoundsException: -1

r.getjTable3().addMouseListener(new MouseAdapter()
    {
        @Override
        public void mousePressed(MouseEvent e) 
        {

            System.out.println(e.getClickCount());
            r.getjButton2().addMouseListener(new MouseAdapter()
           {
                @Override
                public void mousePressed(MouseEvent e) 
                {
                    String nazwa = r.getjTable3().getValueAt(r.getjTable3().getSelectedRow(), 3).toString();
                    System.out.println(r.getjTable3().getSelectedRow());
                    ((DefaultTableModel)r.getjTable3().getModel()).removeRow(r.getjTable3().getSelectedRow());
                    for (Wydarzenie lista1 : lista)
                    {   
                       if(nazwa==lista1.name) 
                       {
                           lista.remove(lista1);

                       }
                    }

                }
           });
        }    
    });
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
Stephan
  • 61
  • 1
  • 1
  • 4
  • `if(nazwa==lista1.name) ` isn't how `String` comparison should be done - generally speaking, it would be better to have the underlying model do this (ie update the data source) – MadProgrammer May 18 '17 at 21:52
  • Something like [this example](http://stackoverflow.com/questions/24625083/how-to-delete-a-row-from-jtable/24626105#24626105) might be an overall better solution, but for what it's worth, I'm not a fan of "click button to delete row", because there are simply so many better ways to achieve this, [as an example](http://stackoverflow.com/questions/25070511/add-jbutton-to-each-row-of-a-jtable/25071138#25071138) – MadProgrammer May 18 '17 at 21:56

0 Answers0