Why do I have to call GraphicsEnvorinment.registerFont() even if I my Font were created from file?

前端 未结 3 992
夕颜
夕颜 2021-01-06 13:02

I\'m developing a web application which use JFreeChart to render chart. However, when server dose not have any Chinese font installed, JFreeChart dose not display Chinese ch

3条回答
  •  孤独总比滥情好
    2021-01-06 13:08

    Why do I have to register font into JVM even if I create my font from file?

    How else is the JVM going to know your font exists?

    Your font has to be registered with the JVM so that Java knows how to draw your font in the graphics environment that JFreeChart uses to render charts.

    How do I make it always use the font I set in order to display character properly in all environment ?

    You need to check that the registerFont() method returns true. If it returns false, your font is not available.

    It looks like you're loading the font correctly. Maybe the file path of your font isn't correct on your server. You might want to try

    getClass().getResource(fontPath);
    

提交回复
热议问题