protected void renderHeaders ( final MBasicTable table , final Table datatable ) throws BadElementException { final int columnCount = table . getColumnCount ( ) ; final TableColumnModel columnModel = table . getColumnModel ( ) ; // size of columns float totalWidth = 0 ; for ( int i = 0 ; i < columnCount ; i ++ ) { totalWidth += columnModel . getColumn ( i ) . getWidth ( ) ; } final float [ ] headerwidths = new float [ columnCount ] ; for ( int i = 0 ; i < columnCount ; i ++ ) { headerwidths [ i ] = 100f * columnModel . getColumn ( i ) . getWidth ( ) / totalWidth ; } datatable . setWidths ( headerwidths ) ; datatable . setWidth ( 100f ) ; // table header final Font font = FontFactory . getFont ( FontFactory . HELVETICA , 12 , Font . BOLD ) ; datatable . getDefaultCell ( ) . setBorderWidth ( 2 ) ; datatable . getDefaultCell ( ) . setHorizontalAlignment ( Element . ALIGN_CENTER ) ; // datatable.setDefaultCellGrayFill(0.75f); String text ; Object value ; for ( int i = 0 ; i < columnCount ; i ++ ) { value = columnModel . getColumn ( i ) . getHeaderValue ( ) ; text = value != null ? value . toString ( ) : "" ; datatable . addCell ( new Phrase ( text , font ) ) ; } // end of the table header datatable . endHeaders ( ) ; }
Effectue le rendu des headers .