this is my first post so any suggestions for how to make my post better would be awesome!
With the help of research from this website, I am able to generate a table that I can change the font of, change the alignment of, and maintain the current look and feel. I cannot however, change the color and am unsure what to do. Any suggestions would be greatly appreciated!
After creating a JTable, I call:
table.getTableHeader().setDefaultRenderer(new HeaderRenderer(table));
private class HeaderRenderer implements TableCellRenderer {
DefaultTableCellRenderer renderer;
public HeaderRenderer(JTable table) {
setOpaque(true);//this is an attempt to change color
renderer = (DefaultTableCellRenderer)
table.getTableHeader().getDefaultRenderer();
renderer.setHorizontalAlignment(JLabel.CENTER);
}
@Override
public Component getTableCellRendererComponent(
JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int col) {
Component cell = renderer.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, col);
setBackground(headerColor);//this is an attempt to change color
//cell.setBackground(headerColor);//this is an attempt to change color
cell.setFont(headerFont);//this successfully changes font
return cell;
}
}
Can anyone point me in a direction or help me create a table header that is able to do be colorable, centered, and has a look and feel of "Nimbus"?