Hello,

 

When I want to delete more than one row in a table I get errors and not all
the rows are deleted. I have to press the delete button few times before all
the selected rows are deleted. Deleting a single selected row works good. 

This is the error I get: 

 

java.lang.ArrayIndexOutOfBoundsException: 7

            at
com.ulcjava.base.application.table.TableRowSorter.convertRowIndexToView(Tabl
eRowSorter.java:16)

            at
com.ulcjava.base.application.ULCTable.convertRowIndexToView(ULCTable.java:44
9)

            at
com.ulcjava.base.application.ULCTable$h_.b(ULCTable$h_.java:0)

            at
com.ulcjava.base.application.ULCTable$h_.sorterChanged(ULCTable$h_.java:28)

            at
com.ulcjava.base.application.table.TableRowSorter.fireRowSorterChanged(Table
RowSorter.java:12)

            at
com.ulcjava.base.application.table.TableRowSorter.sort(TableRowSorter.java:1
85)

            at
com.ulcjava.base.application.table.TableRowSorter.tableChanged(TableRowSorte
r.java:122)

            at
com.ulcjava.base.application.table.AbstractTableModel.fireTableChanged(Abstr
actTableModel.java:37)

            at
com.ulcjava.base.application.table.AbstractTableModel.fireTableRowsDeleted(A
bstractTableModel.java:25)

            at
com.ulcjava.base.application.table.DefaultTableModel.removeRow(DefaultTableM
odel.java:5)

 

These is the code I am using to delete the selected rows from the table:

 

try{

                                    int[] rows = table.getSelectedRows();

                                    

                                    if(rows.length > 0){

                                                int r = 0;

                                                

                                                for(int i = 0; i <
rows.length; i++){

                                                            r =
table.getRowSorter().convertRowIndexToModel(rows[i]);

                                                            

 
tableModel.removeRow(r);

                                                            

                                                }

                                    }

                        }catch(Exception e){

                                    e.printStackTrace();

                        }

 

 

tableModel extends DefaultTableModel.

 

This is how the table row sorter is set:

 

table.setAutoCreateRowSorter(true);       

TableRowSorter tableRowSorter = new TableRowSorter(tableModel);

tableRowSorter.setSortsOnUpdates(true);

table.setRowSorter(tableRowSorter);

                

                

Regards,

Mihaela Westerlaken.          

Reply via email to