开发者

Lag issues with FontMetrics

开发者 https://www.devze.com 2023-02-16 15:52 出处:网络
From the Oracle documentation page on FontMetrics: \"Note that the implementations of these methods are inefficient, so they are usually overridden with more efficient toolkit-specific implementation

From the Oracle documentation page on FontMetrics:

"Note that the implementations of these methods are inefficient, so they are usually overridden with more efficient toolkit-specific implementations."

Can anyone suggest any? The reason I ask is that I implemented开发者_如何转开发 fontMetrics to measure the width of a string, and it took about half a second to calculate it. Since I need to do this several times every time the window is painted, is there a way I can get the width of the string without getting insane lag?

In case I've actually just done something wrong, here's the code causing the lag:

g2d.setFont(new Font("Kootenay", Font.PLAIN, 20));
g2d.setColor(new Color(93, 138, 168));
g2d.fillRect(0, 0, getWidth(), g2d.getFontMetrics().getHeight());

Thanks :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号