Reputation: 13
When I add values to my JTable
and perform save action
the method, it gets performed. The issue is when I enter a single value say "TEST"
in the JTable
, getValueAt(1,0)
returns empty
. When I enter two values, say the table row count is 2, for i = 1
,getValueAt(1,0)
returns value "TEST"
and for i = 2
,getValueAt(2,0)
returns value empty
. I dont know why this is happening.
Code Snippet:
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);
}
}
Do you guys have any idea? If so do post.
Upvotes: 0
Views: 140
Reputation: 3894
Try One of these when you enter the last value :
1) using the enter key
2) tabbing to the next cell
3) clicking on another cell with the mouse
and then try save. Hopefully, that will resolve the issue.
Upvotes: 1