Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要找出java中特定字符的宽度使用了多少像素-例如,字符'3'和'1'的宽度(以像素为单位)。
有任何想法吗?
在图形中,您有 FontMetrics 可以使用方法为您提供答案stringWidth,如下所示:
stringWidth
FontMetrics metrics = g.getFontMetrics(font); int width = metrics.stringWidth("3");