tags:

views:

45

answers:

3

On clicking a button, I want the selected rows to be inverted (non-selected rows should be selected and selected rows should be non-selected).

Is there a build-in method in JTable to do it?

A: 

JTable does not have that feature

Peter
+1  A: 

No, You will have to implement a cutsom ListSelectionListener

Pierre
A: 

JTable doesn't seems to have a built-in way of doing this. So I implemented it with the following code. (Hope this is helpful for someone who is facing a similar issue.)

int[] selectedIndexs = jtable.getSelectedRows();
jtable.selectAll();

for (int i = 0; i < jtable.getRowCount(); i++) {
    for (int selectedIndex : selectedIndexs) {
        if (selectedIndex == i) {
            jtable.removeRowSelectionInterval(i, i);
            break;
        }
    }
}
Sudar