public static String abbreviate(String str,FontMetrics fm,int width){
  int lastblank=0, nchars=0, cumx=0;
  while (cumx < width && nchars < str.length()) {
    if (Character.isWhitespace(str.charAt(nchars))) {
      lastblank=nchars;
    }
    cumx+=fm.charWidth(str.charAt(nchars));
    nchars++;
  }
  if (nchars < str.length() && lastblank > 0) {
    nchars=lastblank;
  }
  return (nchars > 0 ? str.substring(0,nchars) : str);
}

public static String abbreviate ( String str , FontMetrics fm , int width ) { int lastblank = 0 , nchars = 0 , cumx = 0 ; while ( cumx < width && nchars < str . length ( ) ) { if ( Character . isWhitespace ( str . charAt ( nchars ) ) ) { lastblank = nchars ; } cumx += fm . charWidth ( str . charAt ( nchars ) ) ; nchars ++ ; } if ( nchars < str . length ( ) && lastblank > 0 ) { nchars = lastblank ; } return ( nchars > 0 ? str . substring ( 0 , nchars ) : str ) ; }
abbreviate a string by simply truncating it .
