Search code examples
javafontsgraphics2d

Why is my Graphics2D Font changing randomly?


I have the Font "Minecraft" loaded into a static Font object in the Loader class. It gets generated when the program starts and never changes. I have multiple Screens. Each of them accesses the Font object and defines the Font of the String with:

g2.setFont(Loader.font)

Everything worked fine. But as soon as I use the same procedure for the new Start class, the Font just goes back to the default font. On every screen. If I check the name of the font via:

System.out.println(Loader.font.getName());

I get the correct font name ("Minecraft") as output.

I really have no clue why this would happend. How can I fix this or what is the error?

(Here a short video if it wasn´t clear what my problem is)


Solution

  • It was acually pretty simple to fix. I just wasn´t rapainting my JPanel. Somehow everything but the Font got painted automatically. I have no clue why. And I am still confused. At least the problem is fixed now.