public void recalcColumnWidths()
    {
        JTableHeader header = this.getTableHeader();

        TableCellRenderer defaultHeaderRenderer = null;

        if (header != null)
            defaultHeaderRenderer = header.getDefaultRenderer();

        TableColumnModel columns = this.getColumnModel();
        TableModel data = this.getModel();

        int margin = columns.getColumnMargin(); // only JDK1.3

        int rowCount = data.getRowCount();

        int totalWidth = 0;

        for (int i = columns.getColumnCount() - 1; i >= 0; --i)
        {
            TableColumn column = columns.getColumn(i);
            
            int columnIndex = column.getModelIndex();
            
            int width = -1; 

            TableCellRenderer h = column.getHeaderRenderer();
          
            if (h == null)
                h = defaultHeaderRenderer;
            
            if (h != null) // Not explicitly impossible
            {
                Component c = h.getTableCellRendererComponent
                       (this, column.getHeaderValue(),
                        false, false, -1, i);
                    
                width = c.getPreferredSize().width;
            }
       
            for (int row = rowCount - 1; row >= 0; --row)
            {
                TableCellRenderer r = this.getCellRenderer(row, i);
                 
                Component c = r.getTableCellRendererComponent
                   (this,
                    data.getValueAt(row, columnIndex),
                    false, false, row, i);
        
                    width = Math.max(width, c.getPreferredSize().width);
            }

            if (width >= 0)
                column.setPreferredWidth(width + margin); // <1.3: without margin
            else
                ; // ???
            
            totalWidth += column.getPreferredWidth();
        }
    }