Java Utililty Methods Font Text Height

List of utility methods to do Font Text Height

Description

The list of methods to do Font Text Height are organized into topic(s).

Method

intgetStringDrawingHeight(Graphics graphics, String string)
get String Drawing Height
Rectangle2D rect = graphics.getFontMetrics().getStringBounds(string, graphics);
return (int) rect.getHeight() - graphics.getFontMetrics().getDescent();
intgetStringHeight(Component c)
Returns the height of the given component.
FontMetrics metrics = c.getFontMetrics(c.getFont());
int hgt = metrics.getHeight();
return hgt + 2;
doublegetStringHeight(Graphics2D g, String str)
get String Height
FontRenderContext frc = g.getFontRenderContext();
GlyphVector gv = g.getFont().createGlyphVector(frc, str);
return gv.getPixelBounds(null, 0, 0).getHeight();
floatgetStringHeight(Graphics2D graphics2D)
get String Height
FontMetrics fontMetrics = graphics2D.getFontMetrics();
return fontMetrics.getHeight();
intgetTextHeight(String s, FontMetrics fm, Graphics g)
get Text Height
return (int) Math.ceil(fm.getLineMetrics(s, g).getHeight());
intgetTextHeight(String text, Graphics g, String newLineSplit)
get Text Height
return g.getFontMetrics().getHeight() * text.split(newLineSplit).length;
intstringHeight(Graphics2D g2d)
string Height
FontMetrics fm = g2d.getFontMetrics(g2d.getFont());
return fm.getHeight();