icortazar
icortazar

Reputation: 110

JTABLE, When i clear all the rows, if one is selected, that one still apears there

I have a jtable, in which I keep certain information, and I have a 'clear' button that cleans all the information in the table.

The problem is, when I double click on a cell in the table and then I press the clear button, the table is emptied correctly but the selected cell continues appearing in the table as if it had not been deleted. As you can see in the next screenshot.

enter image description here

This is the java code i use to clear the information of the jtable:

public void resetArea(JTable tabla) {

    DefaultTableModel dm = (DefaultTableModel)tabla.getModel();
    while(dm.getRowCount() > 0) {
        dm.removeRow(0);
    }
}

Upvotes: 0

Views: 80

Answers (2)

Sumit
Sumit

Reputation: 38

Try this

DefaultTableModel dm = (DefaultTableModel)tabla.getModel();

while(dm.getRowCount() > 0) {
    dm.removeRow(dm.getRowCount()-1);
}

Upvotes: 1

Joop Eggen
Joop Eggen

Reputation: 109613

That is caused as the cell editor is still shown. First do:

tabla.removeEditor();

Upvotes: 2

Related Questions