int (final @NotNull String string, final @NotNull Rectangle bounds, final @NotNull Graphics2D g) { int centerY = bounds.height / 2; Font font = g.getFont(); FontRenderContext frc = g.getFontRenderContext(); Rectangle stringBounds = font.getStringBounds(string.isEmpty() ? " " : string, frc).getBounds(); return (int)(centerY - stringBounds.height / 2.0 - stringBounds.y); }