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,107
  • 18
  • 130
  • 305
mre
  • 42,270
  • 33
  • 119
  • 166

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,185
  • 12
  • 24
0
((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
  • 1
  • 2