Package com.explodingpixels.widgets
Class TableHeaderUtils
java.lang.Object
com.explodingpixels.widgets.TableHeaderUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 givenJTableHeader
.static int
getSelectedColumn
(JTableHeader tableHeader) Get's the selected column header for the givenJTableHeader
.static TableUtils.SortDirection
getSortDirection
(JTableHeader tableHeader, int columnModelIndex) Get's the pressed column header for the givenJTableHeader
.static boolean
isColumnPressed
(JTableHeader tableHeader, int columnModelIndex) true
if the given column model index is pressed in the givenJTableHeader
.static boolean
isColumnSelected
(JTableHeader tableHeader, int columnModelIndex) true
if the given column model index is selected in the givenJTableHeader
.static void
makeHeaderFillEmptySpace
(JTable table) Installs a customBorder
on the given table'sJTableHeader
that paints any blank area to the right of the last column header with theJTableHeader
'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 givenJTableHeader
as pressed.static TableUtils.SortDirection
toggleSortDirection
(JTableHeader tableHeader, int columnModelIndex) Toggles the sort direction of the given column model index in the givenJTableHeader
.
-
Field Details
-
NO_COLUMN
public static final int NO_COLUMN- See Also:
-
-
Method Details
-
createCornerComponent
Creates a component that paints the table's header background.- Parameters:
table
- theJTable
to create the corner component for.- Returns:
- a
JComponent
that paints the given table's table header background.
-
makeHeaderFillEmptySpace
Installs a customBorder
on the given table'sJTableHeader
that paints any blank area to the right of the last column header with theJTableHeader
's background.- Parameters:
table
- theJTable
from which to get theJTableHeader
to paint the empty column header space for.
-
paintHeader
Paints the given JTable's table default header background at given x for the given width.- Parameters:
graphics
- theGraphics
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
Get's the pressed column header for the givenJTableHeader
.- Parameters:
tableHeader
- theJTableHeader
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
true
if the given column model index is pressed in the givenJTableHeader
.- Parameters:
tableHeader
- theJTableHeader
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:
-
setPressedColumn
Sets the given column for the givenJTableHeader
as pressed. Calling this method installs a hint, which can be used by renders to draw the correct column pressed state. Renders can useisColumnPressed(javax.swing.table.JTableHeader, int)
to determine what state to draw the header for the given index in. header state.- Parameters:
tableHeader
- theJTableHeader
to set the pressed state for.columnModelIndex
- the column model index of the pressed column.
-
getSelectedColumn
Get's the selected column header for the givenJTableHeader
.- Parameters:
tableHeader
- theJTableHeader
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
true
if the given column model index is selected in the givenJTableHeader
. 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
- theJTableHeader
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:
-
getSortDirection
public static TableUtils.SortDirection getSortDirection(JTableHeader tableHeader, int columnModelIndex) Get's the pressed column header for the givenJTableHeader
.- Parameters:
tableHeader
- theJTableHeader
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:
-
toggleSortDirection
public static TableUtils.SortDirection toggleSortDirection(JTableHeader tableHeader, int columnModelIndex) Toggles the sort direction of the given column model index in the givenJTableHeader
. 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 beTableUtils.SortDirection.ASCENDING
. Otherwise the new sort order will beTableUtils.SortDirection.DESCENDING
- Parameters:
tableHeader
- theJTableHeader
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.
-