Working with Headers
Table components often display headers (but only when those table components are placed in scroll pane containers). To manage a table's header, the table component turns to another component known as the table header component.
Table header components are created from the JTableHeader class. When you create a JTable object, the constructor creates a new JTableHeader object to manage the table component's header. That JTableHeader object associates with the table component's column model so that its UI delegate (such as BasicTableHeaderUI) can drag columns and render each column's header cell.
JTable supplies a setTableHeader(JTableHeader h) method that establishes the table header component's JTableHeader object to the object represented by h, and a getTableHeader() method that returns a reference to the table header component's JTableHeader object. Why might you want a reference to a table header component's JTableHeader object? You can use that reference to call JTableHeader methods that, among other things, prevent columns from being resized or reordered during a drag operation. For example, assuming that jt contains a reference to a JTable object, jt.getTableHeader ().setResizingAllowed (false); prevents columns from being resized.