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(),
getRowHeaderFontSize(index).intValue());
if (LabeledTable.this.getRowHeaderTextAttribute(index).equals(TextAttribute.UNDERLINE_ON)) {
headerFont = headerFont.deriveFont(TableFormattingConstants.underlineMap);
}
label.setFont(headerFont);
// Set the row header height to match the table row.
int rowHeight = table.getRowHeight(index);
Dimension d = label.getMinimumSize();
d.setSize(d.getWidth() + 2*ROW_HEADER_MARGIN, rowHeight);
label.setPreferredSize(d);
int r = index - table.getSelectedRow();
if (r >= 0 && r < table.getSelectedRowCount() &&
table.getSelectedColumnCount() == table.getColumnCount()) {
label.setBackground(table.getSelectionBackground());
label.setForeground(table.getSelectionForeground());
} else {
label.setBackground(LabeledTable.this.getRowHeaderBackgroundColor(index));
label.setForeground(table.getTableHeader().getForeground());
}
label.setForeground(getRowHeaderFontColor(index));
label.setBackground(LabeledTable.this.getRowHeaderBackgroundColor(index));
BorderState b = getRowHeaderBorderState(index);
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,
getRowHeaderBorderColor(index));
Border inside = BorderFactory.createEmptyBorder(hasNorth ? 0 : w, hasWest ? 0 : w, hasSouth ? 0 : w, hasEast ? 0 : w);