问题描述
我想提出一个程序中,我需要设置字体一个FontMetrics对象中。我已经创建的FontMetrics,但现在我没有访问Graphics对象了。然而,我想改变的FontMetrics里面的字体,也就是创建一个新的FontMetrics,用新字体,但使用相同的图形上下文。我可以做图形avaliable,但它会占用大量的时间,这将没有任何意义可言这样做。会有人知道它更简单的方法?它作用似乎因此obvius它应该是一个办法,也许我只是失去了一些东西真的很愚蠢的(我看了看文档,没有发现任何)。请帮助!
I am making a program in which I need to set the Font inside a FontMetrics object. I have already created the fontmetrics before, but now I don't have access to the Graphics object anymore. Yet, I want to change the font inside the FontMetrics, that is, create a new FontMetrics, with a new Font, but using the same Graphic context. I could make the Graphics avaliable, but it would take a lot of time and it wouldn't make sense at all to do so. Would anyone know an easier way to it? It seens so obvius it should be a way, maybe I am just missing something really stupid (I looked at the documentation and found nothing). Please help!
推荐答案
也许最简单的方法是使用 JComponent.getFontMetrics(字体)
。这种方法尊重的电流的JComponent
的FontRenderContext
(注意: Component.getFontMetrics
将的不的尊重电流的FontRenderContext
)。
Probably the easiest way would be to use JComponent.getFontMetrics(Font)
. This method respects the JComponent
's current FontRenderContext
(Note:Component.getFontMetrics
will not respect the current FontRenderContext
).
这篇关于FontMetrics对象并入setfont?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!