Reputation: 1
I've created a Java application where there's a JTable
containing data and a button to update database from the table. Is there anyway to clear the selection (row and column) from this JTable
? I've tried JTable#clearSelection()
, and it didn't work.
Upvotes: 0
Views: 2243
Reputation: 205875
The clearSelection()
method "Deselects all selected columns and rows." It only removes the selection highlighting, not the data. To actually clear the cell, you'll have to remove the cell's data from the TableModel
, as outlined here.
public void clearCell(int row, int col) {
// remove the data from your internal data structure
fireTableCellUpdated(row, col);
}
Upvotes: 2