private static Rectangle getPixelBounds(Font font, String text, FontRenderContext context) {
    return font.hasLayoutAttributes()
           ? new TextLayout(text, font, context).getPixelBounds(context, 0, 0)
           : font.createGlyphVector(context, text).getPixelBounds(context, 0, 0);
  }
private static Rectangle getPixelBounds(Font font, String text, FontRenderContext context)