title: How to make JTable's header be highlighted when column selection?
body: <p>I tried to wrote custom renderer, but fail to activate it's features:</p>
  
  <pre><code>public class HeaderRenderer extends JPanel implements TableCellRenderer {
  
          private static final long serialVersionUID = -1247350397731719795L;
  
          @Override
          public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
  
              int modelColumn = table.convertColumnIndexToModel(column);
              /*
              if( table.getSelectedColumn() == modelColumn ) {
                  isSelected = true;
              }
              */
  
              JComponent ans;
  
              if (modelColumn == 0) {
                  ans = new JLabel("&lt;html&gt;&lt;pre&gt;" + getColumnName(column) + "&lt;/pre&gt;&lt;/html&gt;");
              }
              else {
                  ans = new JLabel("&lt;html&gt;&lt;pre&gt;" + String.valueOf(directory.getCorpus(modelColumn - 1)) + "&lt;/pre&gt;&lt;/html&gt;");
  
                  table.getColumnModel().getColumn(table.convertColumnIndexToView(column)).setPreferredWidth(300);
              }
  
              //ans.setBorder(BorderFactory.createLineBorder(Color.black));
  
              ((JLabel) ans).setFont(new Font("SansSerif", Font.PLAIN, 10));
              ans.setForeground(Color.BLUE);
              //((JLabel)ans).setBackground(Color.yellow);
              //ans.setBorder(BorderFactory.createEtchedBorder());
              ans.setBorder(BorderFactory.createLineBorder(Color.black));
  
              if (isSelected) {
                  ans.setBackground(UIManager.getColor("Table.selectionBackground"));
              }
              else {
                  ans.setBackground(getBackground());
              }
  
              ((JLabel) ans).setVerticalAlignment(SwingConstants.TOP);
  
              JTableHeader header = table.getTableHeader();
              Dimension dim = new Dimension();
  
              if (ans.getPreferredSize().height &gt; dim.height) {
                  dim.height = ans.getPreferredSize().height;
                  header.setPreferredSize(dim);
              }
  
              return ans;
  
          }
  
      }
  </code></pre>
  
  <p>Apparently, header is not repainted upon cell selection, so renderer is not run.</p>
  
  <p>How to force it to run?</p>