private void initializeFontMetrics(Font font){
  final BufferedImage temporaryImage=new BufferedImage(10,10,BufferedImage.TYPE_INT_RGB);
  Graphics2D temporaryGraphics2D=(Graphics2D)temporaryImage.getGraphics();
  temporaryGraphics2D.setFont(font);
  fontMetrics=temporaryGraphics2D.getFontMetrics();
  fontCharWidth=fontMetrics.getMaxAdvance();
  fontLineHeight=fontMetrics.getHeight();
}

private void initializeFontMetrics ( Font font ) { final BufferedImage temporaryImage = new BufferedImage ( 10 , 10 , BufferedImage . TYPE_INT_RGB ) ; Graphics2D temporaryGraphics2D = ( Graphics2D ) temporaryImage . getGraphics ( ) ; temporaryGraphics2D . setFont ( font ) ; fontMetrics = temporaryGraphics2D . getFontMetrics ( ) ; fontCharWidth = fontMetrics . getMaxAdvance ( ) ; fontLineHeight = fontMetrics . getHeight ( ) ; }
in order to get the font metrics , a graphics context is required . this function temporarily creates one .
