com.explodingpixels.widgets

## Class TableHeaderUtils

- java.lang.Object
- - com.explodingpixels.widgets.TableHeaderUtils

    public class TableHeaderUtils
    extends Object

### Field Summary

Fields
`static int` `NO_COLUMN`

### Method Summary

Methods
`static JComponent` `createCornerComponent(JTable table)` Creates a component that paints the table's header background.
`static int` `getPressedColumn(JTableHeader tableHeader)` Get's the pressed column header for the given `JTableHeader`.
`static int` `getSelectedColumn(JTableHeader tableHeader)` Get's the selected column header for the given `JTableHeader`.
`static TableUtils.SortDirection` `getSortDirection(JTableHeader tableHeader, int columnModelIndex)` Get's the pressed column header for the given `JTableHeader`.
`static boolean` `isColumnPressed(JTableHeader tableHeader, int columnModelIndex)` `true` if the given column model index is pressed in the given `JTableHeader`.
`static boolean` `isColumnSelected(JTableHeader tableHeader, int columnModelIndex)` `true` if the given column model index is selected in the given `JTableHeader`.
`static void` `makeHeaderFillEmptySpace(JTable table)` Installs a custom `Border` on the given table's `JTableHeader` that paints any blank area to the right of the last column header with the `JTableHeader`'s background.
`static void` `paintHeader(Graphics graphics, JTable table, int x, int width)` Paints the given JTable's table default header background at given x for the given width.
`static void` `setPressedColumn(JTableHeader tableHeader, int columnModelIndex)` Sets the given column for the given `JTableHeader` as pressed.
`static TableUtils.SortDirection` `toggleSortDirection(JTableHeader tableHeader, int columnModelIndex)` Toggles the sort direction of the given column model index in the given `JTableHeader`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### NO_COLUMN

    public static final int NO_COLUMN

See Also:
  Constant Field Values

### Method Detail

#### createCornerComponent

    public static JComponent createCornerComponent(JTable table)

Creates a component that paints the table's header background.

Parameters:
  `table` - the `JTable` to create the corner component for.
Returns:
  a `JComponent` that paints the given table's table header background.

#### makeHeaderFillEmptySpace

    public static void makeHeaderFillEmptySpace(JTable table)

Installs a custom `Border` on the given table's `JTableHeader` that paints any blank area to the right of the last column header with the `JTableHeader`'s background.

Parameters:
  `table` - the `JTable` from which to get the `JTableHeader` to paint the empty column header space for.

#### paintHeader

    public static void paintHeader(Graphics graphics,
                   JTable table,
                   int x,
                   int width)

Paints the given JTable's table default header background at given x for the given width.

Parameters:
  `graphics` - the `Graphics` to paint into.
  `table` - the table that the header belongs to.
  `x` - the x coordinate of the table header.
  `width` - the width of the table header.

#### getPressedColumn

    public static int getPressedColumn(JTableHeader tableHeader)

Get's the pressed column header for the given `JTableHeader`.

Parameters:
  `tableHeader` - the `JTableHeader` to determine the pressed column header for.
Returns:
  the column model index of the pressed column header, or `NO_COLUMN` if no column's header has been pressed.
See Also:
  `isColumnPressed(javax.swing.table.JTableHeader, int)`

#### isColumnPressed

    public static boolean isColumnPressed(JTableHeader tableHeader,
                          int columnModelIndex)

`true` if the given column model index is pressed in the given `JTableHeader`.

Parameters:
  `tableHeader` - the `JTableHeader` to use when determining if the given column is pressed.
  `columnModelIndex` - the column model index to determine the pressed state of.
Returns:
  `true` if the given column is pressed.
See Also:
  `getPressedColumn(javax.swing.table.JTableHeader)`, `setPressedColumn(javax.swing.table.JTableHeader, int)`

#### setPressedColumn

    public static void setPressedColumn(JTableHeader tableHeader,
                        int columnModelIndex)

Sets the given column for the given `JTableHeader` as pressed. Calling this method installs a hint, which can be used by renders to draw the correct column pressed state. Renders can use `isColumnPressed(javax.swing.table.JTableHeader, int)` to determine what state to draw the header for the given index in. header state.

Parameters:
  `tableHeader` - the `JTableHeader` to set the pressed state for.
  `columnModelIndex` - the column model index of the pressed column.

#### getSelectedColumn

    public static int getSelectedColumn(JTableHeader tableHeader)

Get's the selected column header for the given `JTableHeader`.

Parameters:
  `tableHeader` - the `JTableHeader` to determine the selected column header for.
Returns:
  the column model index of the selected column header, or `NO_COLUMN` if no column's header has been pressed.
See Also:
  `isColumnSelected(javax.swing.table.JTableHeader, int)`

#### isColumnSelected

    public static boolean isColumnSelected(JTableHeader tableHeader,
                           int columnModelIndex)

`true` if the given column model index is selected in the given `JTableHeader`.

Note that there is no direct way to set wheter a column is selected or not. Selection is a by-product of set the sort direction on a column.

Parameters:
  `tableHeader` - the `JTableHeader` to use when determining if the given column is selected.
  `columnModelIndex` - the column model index to determine the selected state of.
Returns:
  `true` if the given column is selected.
See Also:
  `getSelectedColumn(javax.swing.table.JTableHeader)`, `setSortDirection(javax.swing.table.JTableHeader, int, com.explodingpixels.widgets.TableUtils.SortDirection)`

#### getSortDirection

    public static TableUtils.SortDirection getSortDirection(JTableHeader tableHeader,
                                            int columnModelIndex)

Get's the pressed column header for the given `JTableHeader`.

Parameters:
  `tableHeader` - the `JTableHeader` containing the column to determine the sort direction for.
  `columnModelIndex` - the column model index to determine the sort direction for.
Returns:
  the `TableUtils.SortDirection` of the given column index.
See Also:
  `setSortDirection(javax.swing.table.JTableHeader, int, com.explodingpixels.widgets.TableUtils.SortDirection)`, `toggleSortDirection(javax.swing.table.JTableHeader, int)`

#### toggleSortDirection

    public static TableUtils.SortDirection toggleSortDirection(JTableHeader tableHeader,
                                               int columnModelIndex)

Toggles the sort direction of the given column model index in the given `JTableHeader`. This also makes the given column selected. If the given column has no sort order set (`TableUtils.SortDirection.NONE`) then the new sort order will be `TableUtils.SortDirection.ASCENDING`. Otherwise the new sort order will be `TableUtils.SortDirection.DESCENDING`

Parameters:
  `tableHeader` - the `JTableHeader` of the column to toggle the sort order for.
  `columnModelIndex` - the column model index to toggle the sort order for.
Returns:
  the new sort order of the column.