Java JTable Header getSelectedColumn(JTableHeader tableHeader)

Here you can find the source of getSelectedColumn(JTableHeader tableHeader)

Description

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

License

Open Source License

Parameter

Parameter Description
tableHeader the JTableHeader to determine the selected column header for.

Return

the column model index of the selected column header, or if no column's header has been pressed.

Declaration

public static int getSelectedColumn(JTableHeader tableHeader) 

Method Source Code

//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";

    /**//from  w  ww.  ja v  a  2 s. co m
     * 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;
    }
}

Related

  1. cleanHeaderCells(JTable table)
  2. createTableHeaderEmptyColumnPainter(final JTable table)
  3. getColumnHeaderWidth(TableColumn col, JTable table)
  4. getHeaderDimension(JTable table, TableColumn tableColumn)
  5. getMaxColumnWidth(JTable aTable, int columnNo, boolean includeColumnHeaderWidth, int columnPadding)
  6. getTableHeaderBackground()
  7. getTableHeaderColor()
  8. headerString(JTable t)
  9. isColumnSelected(JTableHeader tableHeader, int columnModelIndex)