我从excel文档创建图形时间线,并且需要在该事件标记旁边放置事件名称的小标签。其中一些很容易,而且是正确的,但其他人是左对齐的,我需要弄清楚它们的宽度,以便我可以适当地抵消它们。
I'm creating a graphical timeline out of an excel document and I need to have small tags of the name of the event next to the marker for that event. Some of these are easy and are right justified but others are left justified and I need to figure out their width so that I can properly offset them.
window.drawString("7/4-Fourth of July",horizontalIndex-Offset,verticalIndex);目前我使用平均字体大小为10和32的平均像素宽度,但是这并没有真正削减它。有人可以帮助我得到确切的抵消?
Currently I'm averaging the pixel width using an average of both font sizes 10 and 32, but this doesn't really cut it. Can someone help me get the exact offset?
这个线程解释了如何做到这一点:$ b $ b
This thread explains how to do it: Calculate the display width of a string in Java
您应该首先获取字体指标,然后询问度量标准某个字符串有多宽。
You should first get the font metrics, and then ask the metrics how wide a certain string is.
更多推荐
如何确定图形字符串的长度?
发布评论