title: Adjusting row height dynamically on JTable
body: <p>I have found similar questions here on Stackoverflow, but for some reason when I try to implement what is suggested, I get a strange exception.</p>
  
  <p>So I am trying to get adjust some of the heights on 3 of the columns dynamically.</p>
  
  <pre><code>public class AcquisitionTechniquesPanel extends JPanel {
      private static final long serialVersionUID = -3326535610858334494L;
  
      public static final int SIZE_OF_TABLE = 8;
  
      private final JTable table;
      private JCheckBox acquisitionTechniquesDone;
  
      private Object[][] tableData;
      private final String[] columnNames;
  
      public AcquisitionTechniquesPanel() {
          this.columnNames = new String[] { ApplicationStrings.ID, ApplicationStrings.TYPE, "Foo", "Bar", "Biz", "Baz", "Boz", ApplicationStrings.NO_OF_AR_S };
          this.table = new JTable(tableData, columnNames);
  
          initGUI();
      }
  
  
      public void initGUI() {
        table.setColumnSelectionAllowed(
        table.setDragEnabled(false);
        table.setOpaque(true);
        table.getTableHeader().setReorderingAllowed(false);
        table.setModel(new DefaultTableModel());
        JScrollPane scrollPane = new JScrollPane(table);
        scrollPane.setPreferredSize(new Dimension(800, 320));
  
        SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  table.getColumnModel().getColumn(2).setCellRenderer(new VariableRowHeightRenderer());
                  table.getColumnModel().getColumn(3).setCellRenderer(new VariableRowHeightRenderer());
                  table.getColumnModel().getColumn(4).setCellRenderer(new VariableRowHeightRenderer());
              }
          });
      }
  
  public static class VariableRowHeightRenderer extends JLabel implements TableCellRenderer {
          public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
              setText(String.valueOf(value));
              if(getPreferredSize().height &gt; 1)
                  table.setRowHeight(row, getPreferredSize().height);
              return this;
          }
      }
  }
  </code></pre>
  
  <p>Now when I run this code, for some reason I get <code>java.lang.ArrayIndexOutOfBoundsException: 2 &gt;= 0</code>
  I get this exception on the code <code>table.getColumnModel().getColumn(2).setCellRenderer(new VariableRowHeightRenderer());</code>
  Which is strange, because the table should have 8 columns.</p>
  
  <p>Does anyone know what I am doing wrong?</p>
  
  <p><strong>Please note that I am only showing relevant code</strong></p>