Issue
I am trying to calculate the sum of values of a column in a jTable and assign it into a jTextField.
double s=0;
DefaultTableModel tableModel=(DefaultTableModel) jTable33.getModel();
for(int i=0;i<jTable33.getRowCount();i++){
String d= tableModel.getValueAt(i, 3).toString();
double d1=Double.parseDouble(d);
s+=d1;
}
String c=jTextField66.getText().toString();
double cout=Double.parseDouble(c);
s=s+cout;
The jTextField only gets the value of cout ! Please help me solving this.
Solution
I've deleted this line: DefaultTableModel tableModel=(DefaultTableModel) jTable33.getModel();
and changed the for loop a little t:
for(int i=0;i<jTable33.getRowCount();i++){
String d= jTable33.getValueAt(i, 3).toString();
double d1=Double.parseDouble(d);
s+=d1;
}
and it goes just fine. I recommend you to read this JTable tutorial and check the API. Good luck.
Answered By - MariotoA