How to calculate total column value?

Hi, i am very new to java.

I have done a jtable however i need tocalculate row and column values.I have 3 cols. Col1 , Col2,Col3.I have to total up the Columns and rows.

I have looked around for sourcecode but to no avail.

Some are not even working.

Could someone pls help? ?

[321 byte] By [access_javaa] at [2007-11-26 16:29:42]
# 1
Use getValueAt(...) to get the value of each cell. Then you write a loop and add the values. Then use setValueAt(...);
camickra at 2007-7-8 22:54:06 > top of Java-index,Desktop,Core GUI APIs...
# 2
thks for the pointers.is there any sample source code for this?thks
access_javaa at 2007-7-8 22:54:07 > top of Java-index,Desktop,Core GUI APIs...
# 3
How difficult is it to write a loop? Thats the first thing you learn when programming. I don't understand what your problem is.
camickra at 2007-7-8 22:54:07 > top of Java-index,Desktop,Core GUI APIs...
# 4
do some googling on JTable getValue
G_Abubakra at 2007-7-8 22:54:07 > top of Java-index,Desktop,Core GUI APIs...
# 5
Take a look here: http://www.codeguru.com/java/articles/136.shtml
Rodney_McKaya at 2007-7-8 22:54:07 > top of Java-index,Desktop,Core GUI APIs...
# 6
Hi,thanks but this was one of the examples on the internet and it is not working. sigh.....it is supposed to calculate but it doesn't.i m very new to java (2mths) and sample codes would definitely be useful.how else to learn right?
access_javaa at 2007-7-8 22:54:07 > top of Java-index,Desktop,Core GUI APIs...
# 7

//this snippet get each row in column 0

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

Double.valueOf(tblModel.getValueAt(i,0).toString()).intValue();

Double.valueOf(tblModel.getValueAt(i,1).toString()).intValue();

}

gurnah>

G_Abubakra at 2007-7-8 22:54:07 > top of Java-index,Desktop,Core GUI APIs...
# 8

Change getColumnClass like this:

public Class getColumnClass(int col) {

if (col == TOTAL_COLUMN) return Double.class;

return String.class;

}

Rodney_McKaya at 2007-7-8 22:54:07 > top of Java-index,Desktop,Core GUI APIs...