question: public static int calcColumnWidth ( JTable table , int col ) { int result ; TableModel data ; int rowCount ; int row ; int dec ; Component c ; result = calcHeaderWidth ( table , col ) ; if ( result == - 1 ) return result ; data = table . getModel ( ) ; rowCount = data . getRowCount ( ) ; dec = ( int ) Math . ceil ( ( double ) rowCount / ( double ) MAX_ROWS ) ; try { for ( row = rowCount - 1 ; row >= 0 ; row -= dec ) { c = table . prepareRenderer ( table . getCellRenderer ( row , col ) , row , col ) ; result = Math . max ( result , c . getPreferredSize ( ) . width + 10 ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } return result ; }
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 newsgroup de.comp.lang.java with some modifications.<br> Taken from FOPPS/EnhancedTable - http://fopps.sourceforge.net/<br>