Java font: how many pixels are used for the width of a specific character

I need to figure out how many pixels are used for the width of a particular character in java - for example the width of characters "3" and "1" in pixels.

Any ideas?

+3


source to share


1 answer


Inside the graphic, you have FontMetrics that can give you an answer using a method stringWidth

like:



FontMetrics metrics = g.getFontMetrics(font);
int width = metrics.stringWidth("3");

      

+3


source







All Articles