FontMetrics setFont?

好久不见. 提交于 2019-12-07 21:44:57

问题


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).


回答1:


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).



来源:https://stackoverflow.com/questions/10674035/fontmetrics-setfont

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!