0

I want all commas in the cell in one specific column in JTable be under each other like example below. Does anyone know what should i change in my render?

1000,00
   0,12
  12,14
 888,01
  45,123
1458,11

Code:

TableColumn columnPrice = table.getColumnModel().getColumn(3);
TableCellRenderer priceRenderer = new TableCellRenderer() {
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        String price = value.toString().replaceAll("\u20ac ","");
        DecimalFormat decimalFormat = new DecimalFormat("###0.00");
        String formatedValue = decimalFormat.format(Double.parseDouble(price));
        WebLabel label = new WebLabel(formatedValue,SwingConstants.CENTER);
        return label;
    }
};
columnPrice.setCellRenderer(priceRenderer);
itro
  • 7,006
  • 27
  • 78
  • 121
  • 1
    So long as you use a fixed width font, try setting the label's horizontal alignment to `JLabel.RIGHT` – MadProgrammer Nov 26 '12 at 10:15
  • 2
    Even variable pitch fonts typically use the same advance for digits, but the formatter should be working: `45,123`?! Here's an [example](http://stackoverflow.com/a/2834484/230513) using `JLabel.RIGHT`. See the `DecimalFormat` API for better locale handling. – trashgod Nov 26 '12 at 11:36
  • 1
    @itro any issue with EU decimal separator in the JTable, Locale (excl. UK) retruns proper Formatter, please where is issue, the same for Editor..., use NumberFormat instead, if you'll any issue I'll be able post some sscce :-) – mKorbel Nov 26 '12 at 12:08
  • This is issue: Locale locale = new Locale("nl","BE"); – itro Nov 26 '12 at 13:13

0 Answers0