'How to filter row on JTable with condition?

I have a JTable with data from a database. I used filter and this statement to selected true row after filter:

   table.getSelectionModel().addListSelectionListener(                       
       new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                selectedrow = table.convertRowIndexToModel(viewrow);
            }
        }
    );

But I added one JRadioButton to filter with SQL query, and I used the statement: model.fireTableDataChanged(); to reset the data of the table. So when I choose one row then click on the radio button, this program will produce an error like:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 
    Index 0 out of bounds for length 0  

So I think I can fix it if I don't use fireTableDataChanged() by using a filter with a condition. How can I do that or can I do something else to fix it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source