title: JTable variable height of cells and coloring Strings via HTML Tags
body: <p>I have a <code>JTable</code> with cells that have variable heights because of there Content. I accomplished this by using a <code>JTextArea</code> in my <code>TableCellRenderer</code>. I want to Color parts of the <code>String</code> in different colors. <code>JTextPane</code> supports HTML tags and text area doesn't but with text pane it is not possible to change the height of the cell. </p>
  
  <p>Any idea how I can use variable cell heights and coloring of the string with <code>JTable</code>?</p>
  
  <pre><code>public class LineWrapCellRenderer extends JTextPane implements TableCellRenderer {
  
      int rowHeight = 0;  // current max row height for this scan
      final int paddingRight = 4;
      final int paddingLeft = 4;
      Border padding = BorderFactory.createEmptyBorder(5, paddingLeft, 5, paddingRight);
  
  
  @Override
      public Component getTableCellRendererComponent(
              JTable table,
              Object value,
              boolean isSelected,
              boolean hasFocus,
              int row,
              int column){
  
          setContentType("text/html");
          setText(setHTML((String) value));
          setSelectionColor(Color.BLUE);
  
  
          this.setBorder(padding);//Abstände der Zeilen
  
          //markieren fals selektiert
          if (isSelected){
              setBackground(table.getSelectionBackground());
  //          setForeground(table.getSelectionForeground());
          }
          else
          {
              setBackground(table.getBackground());
  //          setForeground(table.getForeground());
          }
  
          // current table column width in pixels
          int colWidth = table.getColumnModel().getColumn(column).getWidth() + table.getIntercellSpacing().width;
  
          // set the text area width (height doesn't matter here)
          Dimension dim = new Dimension(colWidth, 1);
          setSize(dim);
  
          // get the text area preferred height and add the row margin
          int height = getPreferredSize().height + table.getRowMargin();
  
  
          // ensure the row height fits the cell with most lines
          if (height != table.getRowHeight(row)) {
              table.setRowHeight(row, height);
          }
  
          return this;
      }
  </code></pre>
  
  <p>using this code with JTextPane has no effect on the cell height. using the same code with JTextArea the height is adjusted.</p>