Here you can find the source of isColumnSelected(JTableHeader tableHeader, int columnModelIndex)
Parameter | Description |
---|---|
tableHeader | the JTableHeader to use when determining if the given column is selected. |
columnModelIndex | the column model index to determine the selected state of. |
public static boolean isColumnSelected(JTableHeader tableHeader, int columnModelIndex)
//package com.java2s; //License from project: Open Source License import javax.swing.table.JTableHeader; public class Main { public static final int NO_COLUMN = -1; private static final String SELECTED_COLUMN_KEY = "EPJTableHeader.selectedColumn"; /**// w w w . ja v a 2s . c o m * {@code true} if the given column model index is selected in the given {@link JTableHeader}. * <p/> * 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. * * @param tableHeader the {@code JTableHeader} to use when determining if the given column is * selected. * @param columnModelIndex the column model index to determine the selected state of. * @return {@code true} if the given column is selected. * @see #getSelectedColumn(javax.swing.table.JTableHeader) * @see #setSortDirection(javax.swing.table.JTableHeader, int, com.jtechdev.widgets.TableUtils.SortDirection) */ public static boolean isColumnSelected(JTableHeader tableHeader, int columnModelIndex) { int selectedColumn = getSelectedColumn(tableHeader); return selectedColumn >= 0 && selectedColumn == columnModelIndex; } /** * Get's the selected column header for the given {@link JTableHeader}. * * @param tableHeader the {@code JTableHeader} to determine the selected column header for. * @return the column model index of the selected column header, or {@link #NO_COLUMN} if no * column's header has been pressed. * @see #isColumnSelected(javax.swing.table.JTableHeader, int) */ public static int getSelectedColumn(JTableHeader tableHeader) { Object selectedColumnValue = tableHeader.getClientProperty(SELECTED_COLUMN_KEY); return selectedColumnValue != null && selectedColumnValue instanceof Integer ? ((Integer) selectedColumnValue) : NO_COLUMN; } }