DefaultTableCellRenderer doubles not rounded up

All when i add a TableCellRenderer to my JTable

public Component getTableCellRendererComponent(JTable aTable,

Object aNumberValue,

boolean aIsSelected,

boolean aHasFocus,

int aRow,int aColumn){

if (aNumberValue ==null)returnthis;

renderer = super.getTableCellRendererComponent(aTable,

aNumberValue,

aIsSelected,

aHasFocus,

aRow, aColumn);

renderer.setForeground(Color.green);

returnthis;

}

My values in the table which i input are set as following

privatedouble GeneratePrice(){

double d = Math.random() * 100;

return d;

}

So an example value if i don't set the TableCellRender would be 15.22

But when i set the renderer i get a value like 15.23423423423

[1404 byte] By [BenCuthberta] at [2007-11-27 2:21:13]
# 1

I don't understand your problem. How is your renderer to know that you want to round to 2 decimal places? When you write a renderer YOU have to format the values in the way the YOU want. All you have done so far is to change the foreground colour.

Check out java.text.NumberFormat and it's derived classes.

sabre150a at 2007-7-12 2:23:38 > top of Java-index,Java Essentials,Java Programming...
# 2
In the future, Swing related questions should be posted in the Swing forum.After creating the appropriate formatter, you can use this renderer: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=729106
camickra at 2007-7-12 2:23:38 > top of Java-index,Java Essentials,Java Programming...
# 3
Do you have any docs on number formatting in TableCellRendere
BenCuthberta at 2007-7-12 2:23:38 > top of Java-index,Java Essentials,Java Programming...