public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { // Whether we are printing the result or not boolean isPaintingForPrint = false; // Title icon Icon sortIcon = null; if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { Color fgColor = null; Color bgColor = null; if (hasFocus) { fgColor = UIManager.getColor("TableHeader.focusCellForeground"); bgColor = UIManager.getColor("TableHeader.focusCellBackground"); } if (fgColor == null) { fgColor = header.getForeground(); } if (bgColor == null) { bgColor = header.getBackground(); } setForeground(fgColor); setBackground(bgColor); setFont(header.getFont()); isPaintingForPrint = header.isPaintingForPrint(); } if (!isPaintingForPrint && table.getRowSorter() != null) { if (!horizontalTextPositionSet) { // There is a row sorter, and the developer hasn't // set a text position, change to leading. setHorizontalTextPosition(JLabel.LEADING); } List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys(); if (sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) { switch (sortKeys.get(0).getSortOrder()) { case ASCENDING: sortIcon = UIManager.getIcon("Table.ascendingSortIcon"); break; case DESCENDING: sortIcon = UIManager.getIcon("Table.descendingSortIcon"); break; case UNSORTED: sortIcon = UIManager.getIcon("Table.naturalSortIcon"); break; } } } } setIcon(sortIcon); // Title text setText(value == null ? "" : value.toString()); // Title margin setMargin(WebTableStyle.headerMargin); return this; }