Reputation: 205
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
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