While I canβt tell you how to get around this problem, you can use this method to decide when to initialize it:
new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY).createGraphics().getFontMetrics();
This is useful because you can put it anywhere - for example, you could do it while you show the loading screen or something like that. If you use a Graphics object during paint() , then you are only limited to initialization when rendering.
EDIT:
In fact, this can be reduced to:
FontUtilities.getFont2D(new Font("Dialog", 0, 12));
(the slower part is a call to getFont2D , not the Font constructor).
EDIT 2:
And finally, it can be reduced to:
sun.font.FontManagerFactory.getInstance();
The problem is that this singleton class takes a long time to run, since it lists all the system fonts.
EDIT 3:
In this case, there is no good way if you want to use a standard graphics system.
source share