File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTable and getValueAt(int, int) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable and getValueAt(int, int)" Watch "JTable and getValueAt(int, int)" New topic

JTable and getValueAt(int, int)

Stuart Hoffman

Joined: Feb 13, 2004
Posts: 8
I'm having trouble trying to sum values accross the rows in a JTable.
I extended DefaultTableModel for my tableModel then returned a ResultSet via SQLJ to populate the table. The data displays when I run the Applet and I have overridden isCellEditable making cells 1 to 8 editable. Structure of the table is as follows:
ID, Project, hrsMon hrsSun, hrs
int, String, float, float, float, float, float, float, float, float
The first(0) and last(9) columns are not editable. The last column(9) a float is the total. So when a user puts a value in 2-8 and presses enter
the total should be calculated anew.
currently I have something like this:
public Object getValueAt(Float newVal,int row, int col)
BigDecimal sum = new BigDecimal(1);
if(col == 9) // Total column

//sum = new BigDecimal(Float.parseFloat((String)getValueAt(row, 2)) + Float.parseFloat((String)getValueAt(row, 3))
// + Float.parseFloat((String)getValueAt(row, 4)) + Float.parseFloat((String)getValueAt(row, 5))
// + Float.parseFloat((String)getValueAt(row, 6)) + Float.parseFloat((String)getValueAt(row, 7))
// + Float.parseFloat((String)getValueAt(row, 8)));

//sum = BigDecimal.valueOf(Long.parseLong((String)getValueAt(row,2)));
catch (Exception e)
// sum = new BigDecimal(0);


return sum;
return super.getValueAt(row, col);


I finally had to comment out the calculation because i could not get it to compile. I've changed it so many times that I cannot get the code to work. I don't know if BigDecimal is what I want to return or maybe Object or Float? Float makes sense to my newbie mind as that is the type of the field in the database.
Any help is greatly appreciated.
I agree. Here's the link:
subject: JTable and getValueAt(int, int)
It's not a secret anymore!