Class DefaultTableHeaderCellRenderer

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants, TableCellRenderer
Direct Known Subclasses:
MultiColumnSortTableHeaderCellRenderer

public class DefaultTableHeaderCellRenderer extends DefaultTableCellRenderer
A default cell renderer for a JTableHeader.

DefaultTableHeaderCellRenderer attempts to provide identical behavior to the renderer which the Swing subsystem uses by default, the Sun proprietary class sun.swing.table.DefaultTableCellHeaderRenderer.

To apply any desired customization, DefaultTableHeaderCellRenderer may be suitably extended.

See Also:
  • Constructor Details

    • DefaultTableHeaderCellRenderer

      public DefaultTableHeaderCellRenderer()
      Constructs a DefaultTableHeaderCellRenderer.

      The horizontal alignment and text position are set as appropriate to a table header cell, and the opaque property is set to false.

  • Method Details

    • getTableCellRendererComponent

      public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      Returns the default table header cell renderer.

      If the column is sorted, the approapriate icon is retrieved from the current Look and Feel, and a border appropriate to a table header cell is applied.

      Subclasses may overide this method to provide custom content or formatting.

      Specified by:
      getTableCellRendererComponent in interface TableCellRenderer
      Overrides:
      getTableCellRendererComponent in class DefaultTableCellRenderer
      Parameters:
      table - the JTable.
      value - the value to assign to the header cell
      isSelected - This parameter is ignored.
      hasFocus - This parameter is ignored.
      row - This parameter is ignored.
      column - the column of the header cell to render
      Returns:
      the default table header cell renderer
    • getIcon

      protected Icon getIcon(JTable table, int column)
      Overloaded to return an icon suitable to the primary sorted column, or null if the column is not the primary sort key.
      Parameters:
      table - the JTable.
      column - the column index.
      Returns:
      the sort icon, or null if the column is unsorted.
    • getSortKey

      protected RowSorter.SortKey getSortKey(JTable table, int column)
      Returns the current sort key, or null if the column is unsorted.
      Parameters:
      table - the table
      column - the column index
      Returns:
      the SortKey, or null if the column is unsorted