Default Table Header Cell Renderer
Posted by Darryl Burke on February 27, 2009
The javax.swing package and its subpackages provide a fairly comprehensive set of default renderer implementations, suitable for customization via inheritance. A notable omission is the lack of a default renderer for a JTableHeader in the public API. The renderer used by default is a Sun proprietary class, sun.swing.table.DefaultTableCellHeaderRenderer, which cannot be extended.
DefaultTableHeaderCellRenderer seeks to fill this void, by providing a rendering designed to be identical with that of the proprietary class, with one difference: the vertical alignment of the header text has been set to BOTTOM, to provide a better match between DefaultTableHeaderCellRenderer and other custom renderers.
The name of the class has been chosen considering this to be a default renderer for the cells of a table header, and not the table cells of a header as implied by the proprietary class name.
To use the renderer, set it to a JTable’s header:
This will not lead to any observable change in the table header’s rendering in the default Metal L&F. The strength of DefaultTableHeaderCellRenderer lies in its ability to be extended and customized. A future posting will provide a subclass to render the table header vertically, making use of the already published VerticalLabelUI.
DefaultTableHeaderCellRenderer extends javax.swing.table.DefaultTableCellRenderer.