1

I've tried the following,

foo.getTableHeader().setLayout(new FlowLayout(FlowLayout.LEFT));

where foo is the JTable instance, but the text remains centered. Why?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
mre
  • 43,520
  • 33
  • 120
  • 170

2 Answers2

3

Your code affects where the table header itself is positioned, not the items within each header. You need to call getTableHeader().setDefaultRenderer(xxx) with something that left-aligns the types you care about.

Mel Nicholson
  • 3,225
  • 14
  • 24
1
((DefaultTableCellRenderer)table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(JLabel.LEFT)

The easiest way I found working for me. Of course, you can use another centering constant for JLabel.LEFT.

Briatore
  • 11
  • 3