code learner
code learner

Reputation: 11

how to clear data in a jtable

I have two JTables in a JScrollPane (table1 and Table2) when I select any row in table1 some information related to that row is displayed in table 2. My issue is if I select one row and then select another row the data related to 2nd row is being appended in table 2 instead I want table 2 to show only 2nd row's data when I select 2nd row and not both row 1 and row 2 data. Can anyone please help.

Upvotes: 0

Views: 1579

Answers (1)

Rob Wagner
Rob Wagner

Reputation: 4421

The easiest way is to just reset the table model of your second table before adding in the new data. Here is a simple example of a reset method you could use.

void clear() {
  model.setRowCount(0);
}

Upvotes: 2

Related Questions