FontMetrics setFont?

305 Views Asked by At

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

There are 1 best solutions below

1
On

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