0

This is my table:

enter image description here

I like that 61 and 29 and 2013/09/20 be in the middle of cell, Not in the left side!

How can do it?

Sajad
  • 2,273
  • 11
  • 49
  • 92

1 Answers1

4

You can do this, which sets the horizontal alignment for each column by overriding the renderer.

DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setHorizontalAlignment(JLabel.CENTER);
for(int i = 0; i < columnCount; i++){
    table.getColumnModel().getColumn(i).setCellRenderer(render);
}
Obicere
  • 2,999
  • 3
  • 20
  • 31
  • 1
    Decided to change my comment as you asnwered my previous asking why not change the alignment of the current ones. One problem your solution might brings is if the actual renderers provide custom colors or other rendering tricks, those will be lost. – Jonathan Drapeau Nov 13 '13 at 20:33
  • Agreed, for example, the last column is a Date which is probably using a DateRenderer. – camickr Nov 13 '13 at 20:48