gpt4 book ai didi

java - 将数据插入jtable

转载 作者:行者123 更新时间:2023-12-01 13:14:09 25 4
gpt4 key购买 nike

嘿,我想通过单击按钮将文本字段中的数据添加到 jtable 中。但是当我这样做时,它会替换第一行而不是添加另一行。

这是我使用的示例代码

  DefaultTableModel  model = (DefaultTableModel) jTable1.getModel();
model.setRowCount(0);
model.addRow(new Object[]{i, jTextField2.getText(), new Integer(jTextField3.getText()), new Double(jTextField4.getText()), new Double(jTextField5.getText())});

我想在每次单击jbutton时向表格添加另一行

最佳答案

我猜您的问题出在 model.setRowCount(0) 中。

来自here

Sets the number of rows in the model. If the new size is greater than the current size, new rows are added to the end of the model If the new size is less than the current size, all rows at index rowCount and greater are discarded.

更多信息How to use Tables

关于java - 将数据插入jtable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22595579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com