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.
java/zylib/src/main/java/com/google/security/zynamics/zylib/gui/CodeDisplay/CodeDisplay.java