user1917209
user1917209

Reputation: 205

Java Font :how many pixels are being used for the width of a particular character

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

Any Ideas?

Upvotes: 3

Views: 1537

Answers (1)

siame
siame

Reputation: 8657

Within graphics you have FontMetrics which can give you the answer using the method stringWidth, like so:

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

Upvotes: 4

Related Questions