Share the post "How To Show JTableHeader On A JTable With No JScrollPane"
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.
|
1 2 3 4 |
JPanel panel = new JPanel(); panel.setsLayout(new BorderLayout(0, 0)); panel.add(table.getTableHeader(), BorderLayout.NORTH); panel.add(table, BorderLayout.CENTER); |
That should make it display those table headers.