Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Row & Column totals in jTable

 
Mike Chilton
Greenhorn
Posts: 2
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create row and column totals in a jTable. The user can input cell values using 3 text fields (to identify the row, column & value) and a button to add it to the table. The user should then be able to click on a second button which will sum all columns and rows and display the column sums in the last row and the row sums in the last column. Unfortunately I receive an error "NullPointerException" and the program breaks at line 135: salesTotal[row] += Double.valueOf(value).doubleValue();

I am under the impression that the cell values are objects and must be converted to (first) Strings and (second) doubles before you can total them, but not sure how to do this. The program breaks before it can set the value in the appropriate cell, so I haven't been able to test that part yet.

Here is the code.
 
Hitesh P Patel
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which file you are trying to upload ?
If you are talking about code then use code tags to submit your code.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> The user should then be able to click on a second button which will sum all columns and rows...

that's a backward step - use a TableModelListener
 
Mike Chilton
Greenhorn
Posts: 2
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I wasn't asking for help with design decisions--just how to code row and column totals and put the results into a column and row.
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Chilton wrote:Sorry, I wasn't asking for help with design decisions

Then I won't advise you that things related to values should be kept in the model, not in the view.

Pity that, seeing as an extended DefaultTableModel with a few overrides provides such a clean solution.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic