When creating a JTable, a JScrollPane accompanies it in many cases. However, there may be times where you do not want the JTable added to the JScrollPane.

The problem I encountered was finding out the JTableHeader could not be seen. I am not sure if there is a solution to this but what I did was to get a reference to the JTableHeader and add it as another component on top of the JTable.

Add both the JTable and JTableHeader in a container like JPanel and set its layout to BorderLayout. See example.

That should make it display those table headers.

Sure. Setting a JTable column header’s background color is very easy. Just call

But once you run it, there may be times you will not see any changes. I am not sure if this happens all the time but this surely did happen to me and it took me a very, very long time to figure out how to make this work.

All it took was one method call.

Do that, and your background color should now appear.

Related Posts Plugin for WordPress, Blogger...