question: public static int calcColumnWidth ( JTable table , int col ) { int width = calcHeaderWidth ( table , col ) ; if ( width == - 1 ) { return width ; } TableColumnModel columns = table . getColumnModel ( ) ; TableModel data = table . getModel ( ) ; int rowCount = data . getRowCount ( ) ; columns . getColumn ( col ) ; try { for ( int row = rowCount - 1 ; row >= 0 ; -- row ) { Component c = table . prepareRenderer ( table . getCellRenderer ( row , col ) , row , col ) ; width = Math . max ( width , c . getPreferredSize ( ) . width + 10 ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } return width ; }
target:  Calculates the optimal width for the column of the given table. The calculation is based on the preferred width of the header and cell renderer. <br> Taken from the newsgoup de.comp.lang.java with some modifications.<br> Taken from FOPPS/EnhancedTable - http://fopps.sourceforge.net/<br>