Package com.explodingpixels.widgets
Class TableHeaderUtils
- java.lang.Object
-
- com.explodingpixels.widgets.TableHeaderUtils
-
public class TableHeaderUtils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static intNO_COLUMN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static javax.swing.JComponentcreateCornerComponent(javax.swing.JTable table)Creates a component that paints the table's header background.static intgetPressedColumn(javax.swing.table.JTableHeader tableHeader)Get's the pressed column header for the givenJTableHeader.static intgetSelectedColumn(javax.swing.table.JTableHeader tableHeader)Get's the selected column header for the givenJTableHeader.static TableUtils.SortDirectiongetSortDirection(javax.swing.table.JTableHeader tableHeader, int columnModelIndex)Get's the pressed column header for the givenJTableHeader.static booleanisColumnPressed(javax.swing.table.JTableHeader tableHeader, int columnModelIndex)trueif the given column model index is pressed in the givenJTableHeader.static booleanisColumnSelected(javax.swing.table.JTableHeader tableHeader, int columnModelIndex)trueif the given column model index is selected in the givenJTableHeader.static voidmakeHeaderFillEmptySpace(javax.swing.JTable table)Installs a customBorderon the given table'sJTableHeaderthat paints any blank area to the right of the last column header with theJTableHeader's background.static voidpaintHeader(java.awt.Graphics graphics, javax.swing.JTable table, int x, int width)Paints the given JTable's table default header background at given x for the given width.static voidsetPressedColumn(javax.swing.table.JTableHeader tableHeader, int columnModelIndex)Sets the given column for the givenJTableHeaderas pressed.static TableUtils.SortDirectiontoggleSortDirection(javax.swing.table.JTableHeader tableHeader, int columnModelIndex)Toggles the sort direction of the given column model index in the givenJTableHeader.
-
-
-
Field Detail
-
NO_COLUMN
public static final int NO_COLUMN
- See Also:
- Constant Field Values
-
-
Method Detail
-
createCornerComponent
public static javax.swing.JComponent createCornerComponent(javax.swing.JTable table)
Creates a component that paints the table's header background.- Parameters:
table- theJTableto create the corner component for.- Returns:
- a
JComponentthat paints the given table's table header background.
-
makeHeaderFillEmptySpace
public static void makeHeaderFillEmptySpace(javax.swing.JTable table)
Installs a customBorderon the given table'sJTableHeaderthat paints any blank area to the right of the last column header with theJTableHeader's background.- Parameters:
table- theJTablefrom which to get theJTableHeaderto paint the empty column header space for.
-
paintHeader
public static void paintHeader(java.awt.Graphics graphics, javax.swing.JTable table, int x, int width)Paints the given JTable's table default header background at given x for the given width.- Parameters:
graphics- theGraphicsto 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(javax.swing.table.JTableHeader tableHeader)
Get's the pressed column header for the givenJTableHeader.- Parameters:
tableHeader- theJTableHeaderto determine the pressed column header for.- Returns:
- the column model index of the pressed column header, or
NO_COLUMNif no column's header has been pressed. - See Also:
isColumnPressed(javax.swing.table.JTableHeader, int)
-
isColumnPressed
public static boolean isColumnPressed(javax.swing.table.JTableHeader tableHeader, int columnModelIndex)trueif the given column model index is pressed in the givenJTableHeader.- Parameters:
tableHeader- theJTableHeaderto use when determining if the given column is pressed.columnModelIndex- the column model index to determine the pressed state of.- Returns:
trueif the given column is pressed.- See Also:
getPressedColumn(javax.swing.table.JTableHeader),setPressedColumn(javax.swing.table.JTableHeader, int)
-
setPressedColumn
public static void setPressedColumn(javax.swing.table.JTableHeader tableHeader, int columnModelIndex)Sets the given column for the givenJTableHeaderas 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- theJTableHeaderto set the pressed state for.columnModelIndex- the column model index of the pressed column.
-
getSelectedColumn
public static int getSelectedColumn(javax.swing.table.JTableHeader tableHeader)
Get's the selected column header for the givenJTableHeader.- Parameters:
tableHeader- theJTableHeaderto determine the selected column header for.- Returns:
- the column model index of the selected column header, or
NO_COLUMNif no column's header has been pressed. - See Also:
isColumnSelected(javax.swing.table.JTableHeader, int)
-
isColumnSelected
public static boolean isColumnSelected(javax.swing.table.JTableHeader tableHeader, int columnModelIndex)trueif 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- theJTableHeaderto use when determining if the given column is selected.columnModelIndex- the column model index to determine the selected state of.- Returns:
trueif 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(javax.swing.table.JTableHeader tableHeader, int columnModelIndex)
Get's the pressed column header for the givenJTableHeader.- Parameters:
tableHeader- theJTableHeadercontaining the column to determine the sort direction for.columnModelIndex- the column model index to determine the sort direction for.- Returns:
- the
TableUtils.SortDirectionof 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(javax.swing.table.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- theJTableHeaderof 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.
-
-