• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Row & Column totals in jTable

 
Greenhorn
Posts: 2
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
See where your hand is? Not there. It's next to this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic