@Override
  public Dimension getPreferredSize() {
    if (myPrefSize == null) {
      Dimension dimension = new Dimension();
      int rowHeight = 0;
      for (int column = 0; column < getColumnCount(); column++) {
        int columnWidth = 0;
        for (int row = 0; row < getRowCount(); row++) {
          final TableCellRenderer renderer = getCellRenderer(row, column);
          if (renderer != null) {
            final Object value = getValueAt(row, column);
            final Component component = renderer.getTableCellRendererComponent(this, value, true, true, row, column);
            if (component != null) {
              final Dimension size = component.getPreferredSize();
              rowHeight = Math.max(size.height, rowHeight);
              columnWidth = Math.max(size.width, columnWidth);
            }
          }
        }
        getColumnModel().getColumn(column).setWidth(columnWidth + 5);
        dimension.width += columnWidth + 5;
      }
      dimension.height = getRowCount() * rowHeight;
      myPrefSize = dimension;
    }
    return myPrefSize;
  }
@Override
  public Dimension getPreferredSize()