JTable: Custom header cell renderer loses default behavior/look
843806Apr 8 2009 — edited Apr 11 2009I'm fine with everything about the default table header rendering except the text alignment. I am using a Windows LaF, and it left-justifies all column headers. I want the headers to either be centered or to follow the custom cell rendering for the column (some left, some centered, some right). Not sure which looks best, but I know I want control on a column-by-column basis.
So I created a custom header cell renderer that extends DefaultTableCellRenderer and assigned it to my column headers. I get the cell Component (JLabel) and successfully set the horizontal alignment based on custom column configuration info I have in my custom table model. The header text alignment is now under my control and works as expected. Piece of cake...
The problem is that I've lost all the other default behavior of the column header such as:
- The header does not get underlined when you mouse over
- You can't click on the header to sort by that column
- colors have changed (no longer black text on white background)
I can manually set the column header colors easy enough, but don't understand why they changed. And where did all the built-in mouse stuff go?
Based on searching this site, it appears SunSolve has a solution, but I am not worthy to view it (no support plan).
Thanks in advance for any insights or links to example code. I've been searching/reading for a while now and haven't seen this particular issue addressed anywhere.