views:

202

answers:

2

Given a JTable where one of the columns contains a number, how do I display this number as a currency? I.e. 5 should display as $5.00 etc.

Can this be done directly on the JTable after it has been populated with data, or do I have to do this earlier? Thanks.

+2  A: 

There are a couple of ways to approach this. The up-front easiest might be to simply populate that column with a custom object that implements the currency formatting in its toString() method.

The other is to use a custom cell renderer. Here is some sample code for setting that up. It would have the advantage of being "done directly on the JTable after it has been populated with data."

Yishai
+1  A: 

Table Format Renderers shows how numbers and dates can easily be formatted.

camickr