gpt4 book ai didi

java - 使用 getValueAt() 方法时如何避免空值?

转载 作者:行者123 更新时间:2023-12-02 11:06:31 29 4
gpt4 key购买 nike

当我向 JTable 添加值并执行该方法的保存操作时,它就会被执行。问题是,当我在 JTable 中输入单个值(例如 "TEST")时,getValueAt(1,0) 返回 empty .当我输入两个值时,假设表行数为 2,对于 i = 1getValueAt(1,0) 返回值 "TEST" 对于 i = 2getValueAt(2,0) 返回值 empty。我不知道为什么会发生这种情况。

代码片段:

   private void jbtSaveActionPerformed(java.awt.event.ActionEvent evt) {                                        

DefaultTableModel tablemodel = (DefaultTableModel) jTable6.getModel();
LinkedList<String> paramList = new LinkedList<String>();

for (int i = 0; i < tablemodel.getRowCount(); i++) {

System.out.println("Table row count :" + tablemodel.getRowCount());
System.out.println("i " + i);
String rowValue = (String) tablemodel.getValueAt(i, 0);
paramList.add(rowValue);

System.out.println("row value :" + rowValue);
System.out.println(paramList.get(i));

}
SamIntegerResult intRes1 = svc.saveTSAServices(token, tsaservice, paramList, idList);

if (intRes1.isSuccess()) {
JOptionPane.showMessageDialog(this, new JLabel("Saved successfully", JLabel.CENTER), "Save TSA Service", JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, "Error saving to database", "Error", JOptionPane.ERROR_MESSAGE);
}

}

你们有什么想法吗?如果是这样,请发布。

最佳答案

输入最后一个值时尝试其中一个:

1) using the enter key

2) tabbing to the next cell

3) clicking on another cell with the mouse

然后尝试保存。希望这能解决问题。

关于java - 使用 getValueAt() 方法时如何避免空值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50921181/

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