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

How to avoid empty value when using getValueAt() method?

当我将值添加到 JTable 并执行 save action 方法时,它会被执行。问题是当我在 JTable, getValueAt(1,0) returns empty 中输入单个值时说 "TEST" 。当我输入两个值时,假设 table 行计数为 2,对于 i = 1getValueAt(1,0) returns 值 "TEST" 和对于 i = 2getValueAt(2,0) returns 值 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);
    }

} 

你们有什么想法吗?如果是 post.

输入最后一个值时尝试以下方法之一:

1) using the enter key

2) tabbing to the next cell

3) clicking on another cell with the mouse

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