0

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 *)

Community
  • 1
  • 1
pioupiou1211
  • 353
  • 4
  • 16

1 Answers1

2

The this you are using refers to TableCellRenderer.

You have to use

TopLevelClassName.this
Daniel Bickler
  • 1,119
  • 13
  • 29
  • Thanks that's exactly what I was looking for. I will accept your answer in 10 minutes (didn't know that there was a delay to accept answers). – pioupiou1211 Apr 04 '17 at 13:41