final TableCellRenderer defaultHeaderRenderer = table.getTableHeader().getDefaultRenderer();
final TableCellRenderer headerRenderer = new TableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel label = (JLabel) defaultHeaderRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
ContentAlignment alignment = LabeledTable.this.getColumnHeaderAlignment(column);
label.setHorizontalAlignment(alignment.getComponentAlignment());
Border padding = BorderFactory.createEmptyBorder(0, 5, 0, 5);
if (headerBorder != null) label.setBorder(headerBorder);
label.setBorder(BorderFactory.createCompoundBorder(label.getBorder(), padding));
Font headerFont = new Font(LabeledTable.this.getColumnHeaderFontName(column).name(),
getColumnHeaderFontStyle(column).intValue(),
getColumnHeaderFontSize(column).intValue());
if (LabeledTable.this.getColumnHeaderTextAttribute(column).equals(TextAttribute.UNDERLINE_ON)) {
headerFont = headerFont.deriveFont(TableFormattingConstants.underlineMap);
}
label.setFont(headerFont);
// Set the table header height to fit the font size
int rowHeight = label.getFont().getSize() + 2;
Dimension d = label.getMinimumSize();
d.setSize(d.getWidth() + 2*ROW_HEADER_MARGIN, rowHeight);
label.setPreferredSize(d);
int c = column - table.getSelectedColumn();
if (c >= 0 && c < table.getSelectedColumnCount() &&
row == -1 && table.getSelectedRowCount() == table.getRowCount()) {
label.setBackground(table.getSelectionBackground());
label.setForeground(table.getSelectionForeground());
} else {
label.setBackground(table.getTableHeader().getBackground());
label.setForeground(table.getTableHeader().getForeground());
}
label.setForeground(getColumnHeaderFontColor(column));
label.setBackground(LabeledTable.this.getColumnHeaderBackgroundColor(column));
BorderState b = getColumnHeaderBorderState(column);
if (b != null) {
boolean hasNorth = b.hasNorthBorder();
boolean hasWest = b.hasWestBorder();
boolean hasSouth = b.hasSouthBorder();
boolean hasEast = b.hasEastBorder();
int w = TableCellFormatter.getBorderWidth();
Border outside = BorderFactory.createMatteBorder(hasNorth ? w : 0, hasWest ? w : 0, hasSouth ? w : 0, hasEast ? w : 0,
getColumnHeaderBorderColor(column));
Border inside = BorderFactory.createEmptyBorder(hasNorth ? 0 : w, hasWest ? 0 : w, hasSouth ? 0 : w, hasEast ? 0 : w);
label.setBorder(BorderFactory.createCompoundBorder(outside,inside));
}
return label;
}
};
table.getTableHeader().setDefaultRenderer(headerRenderer);
rowHeaders = new JList(model.getRowLabelModel());
rowHeaders.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
rowHeaders.setCellRenderer(new ListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected,
boolean hasFocus) {
JLabel label = (JLabel) defaultHeaderRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, 0, index);
ContentAlignment alignment = LabeledTable.this.getRowHeaderAlignment(index);
label.setHorizontalAlignment(alignment.getComponentAlignment());
Border padding = BorderFactory.createEmptyBorder(0, 5, 0, 5);
if (headerBorder != null) label.setBorder(headerBorder);
label.setBorder(BorderFactory.createCompoundBorder(label.getBorder(), padding));
Font headerFont = new Font(LabeledTable.this.getRowHeaderFontName(index).name(),
getRowHeaderFontStyle(index).intValue(),