aspose file tools*
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 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable and getValueAt(int, int)" Watch "JTable and getValueAt(int, int)" New topic
Author

JTable and getValueAt(int, int)

Stuart Hoffman
Greenhorn

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,.................................total 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
{
try
{

//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)
{
e.printStackTrace();
System.out.println(e.getMessage());
// sum = new BigDecimal(0);
}

setValueAt(sum,row,9);

return sum;
}
else
{
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.
Thanks
Stuart
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JTable and getValueAt(int, int)
 
Similar Threads
JTable
JTable JCheckBox Cell Editor works on strings -- badly
problem displaying jtable values
jtable
JTable Cell data validation/blank cell problem