This content has been marked as final. Show 4 replies
I could use the java.text.DecimalFormat when I need to put a value somewhere on the screen (like the textbox in the example).
But what's needed to use the BigDecimal as an object in a JTable? The JTable display's it's objectvalues and the user can change these values.
For a BigDecimal, the value is displayed 'right-aligned' as numbers and the user can only enter valid numbers. When the BigDecimal is coverted to a textvalue,
1) the column with figures becomes cluttered (left-aligned text)
2) there is no way of autocheck for correct values...
Write your own cell renderer then using DecimalFormat you can format it however you like. Check out the JTable section in the Swing tutorial.
The semantics of BigDecimal.toString() changed in version 1.5. Now to get the plain string you need to use the toPlainString() method.
bdvalue.setText("Value=" + bd.toPlainString());