This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

calculating sum for numeric(currency) columns and displaying it with currency code in a JTable  RSS feed

 
yangel botha
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am a beginner with swing. working on a project which has its own client framework, we have customized swing components. for a new requirement, I need to display the sum of the numerics in the last column of a JTable and append the currency code with that. something like this ' 2500.00 (USD)' . The current formatter application is using is the NumberFormatter and allowes only numerics in the table cells. The data type of these columns is BigDecimal. with the current formatter and renderrer I can't display the sum with appending the currency code. I would like to know if it is possible to do so ?
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can write a cell renderer to do anything which is possible in the Java language. And your requirement is clearly one of those possible things.
 
yangel botha
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul, the thing is that the column definitions in our app are given in the XMLs, the data type for this currency field is BigDecimal..now if I want the sum with currency code, the renderer does not allow it as it allows only numerics..the requirement is that still it should not allow anything other than a numerical value but the sum should contain the currency code, my column def contains the currency code also but still can't understand how to show the sum with currency code, what kind of renderer should I write now ?
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea. You're going to have to unscramble all of the conflicting requirements which were packed into what you just posted. Once you understand the requirements, then you can ask how to implement them.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yangel botha wrote: the renderer does not allow it as it allows only numerics..the requirement is that still it should not allow anything other than a numerical value

I think you are getting confused between 'editor' and 'renderer' - renderer just does the display, it is the editor that does the validations that you are talking about. So, the renderer can use the NumberFormat.getCurrencyInstance() to display the value along with the currency and the editor will take care of 'validating' the inputs when the user edits it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!