I'm trying to use that code https://stackoverflow.com/a/8187799 but with one change: I'm extending my class to JTable so that I can do whatever I want with it when I'm done. Then, I simply just have to replace the occurences of table
by this
. But in this part of the code, it doesn't work because I'm overriding some method:
headerTable.getColumnModel().getColumn(0).setCellRenderer(new TableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable x, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
boolean selected = getSelectionModel().isSelectedIndex(row);
Component component = getTableHeader().getDefaultRenderer().getTableCellRendererComponent(*this*, value, false, false, -1, -2);
((JLabel) component).setHorizontalAlignment(SwingConstants.CENTER);
if (selected) {
component.setFont(component.getFont().deriveFont(Font.BOLD));
component.setForeground(Color.red);
} else {
component.setFont(component.getFont().deriveFont(Font.PLAIN));
}
return component;
}
});
How can I use this
as I intend to? (The this
that is causing me troubles is between *
)