简体   繁体   English

如何清除jtable中的数据

[英]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. 当我选择table1中的任何行时,我在JScrollPane(table1和Table2)中有两个JTable。表2中显示了与该行相关的一些信息。我的问题是如果我选择一行然后选择另一行与第二行相关的数据正在附加在表2中,而我希望表2在我选择第二行而不是第一行和第二行数据时仅显示第二行的数据。 Can anyone please help. 谁能请帮忙。

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM