EDDYCHAMOUN
EDDYCHAMOUN

Reputation: 1

How to clear selection from JTable?

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

Answers (1)

trashgod
trashgod

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

Related Questions