How can I determine how many pixels are in a specific letter of a specific Font i开发者_StackOverflown Java?
If you have the font loaded as a Font
object, you can create a new FontMetrics
object (or one of its children if your graphics toolkit has one) and its charWidth(char ch)
method to determine its size. The units aren't listed in the manual, but I'm assuming pixels.
Likewise, there's a stringWidth
method to get the width of an entire String
.
精彩评论