question: private int calculateMaxCharacterWidthBasedOnPixelWidth ( ) { String testWidthString = "" ; for ( int i = 0 ; i < 25 ; i ++ ) { testWidthString = testWidthString + "A." ; } BufferedImage temp = new BufferedImage ( 100 , 100 , BufferedImage . TYPE_INT_ARGB ) ; Graphics2D tempG2d = temp . createGraphics ( ) ; ; FontMetrics metrics = tempG2d . getFontMetrics ( this . labelFont ) ; int strWidth = metrics . stringWidth ( testWidthString ) ; while ( strWidth > this . maxPixelWidth ) { testWidthString = testWidthString . substring ( 0 , testWidthString . length ( ) - 1 ) ; strWidth = metrics . stringWidth ( testWidthString ) ; } return testWidthString . length ( ) ; }
target:  Calculates the max number of characters this font can have within the given pixel width