Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Joe Ess
  • salvin francis

JTable and getValueAt(int, int)

Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!