开发者

Lag issues with FontMetrics

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜