Java – how do I determine the length of a graphic string?

I'm creating a graphical timeline from an excel document. I need to add a small label of the event name next to the tag of the event Some of them are easy to align correctly, but others make sense. I need to figure out their width so that I can offset them appropriately

window.drawString("7/4-Fourth of July",horizontalIndex-Offset,verticalIndex);

At present, my average pixel width uses the average two font sizes of 10 and 32, but this is not really cut Can someone help me find the exact offset?

Solution

This thread explains how to:

You should first get the font indicator and then ask for the width of a string

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>