private int stringWidth ( FontMetrics fm , String text ) { int w = fm . stringWidth ( text ) ; if ( wordSpacing != null ) { //count spaces and add float add = 0.0f ; for ( int i = 0 ; i < text . length ( ) ; i ++ ) { if ( text . charAt ( i ) == ' ' ) add += wordSpacing ; } w = Math . round ( w + add ) ; } return w ; }
Computes the final width of a string while considering word - spacing