Changing font size in Java

旧街凉风 提交于 2020-01-02 05:37:15

问题


I got my own custom font working in Java, but I have one problem, the font size seems to be staying at 1. I tried font.deriveFont(20.0f); at my initialize method, but, it didn't resize.

try {
    font = Font.createFont(Font.TRUETYPE_FONT, new File("D:/StanJump/mailrays.ttf"));
    font.deriveFont(20.0f);
} catch (Exception ex) {}

This is my code to create the font and try to change the size, but this didn't work. Any help on making it work, please?


回答1:


deriveFont returns a reference to a new font instance. Thus you need to assign it back to font, e.g.

font = font.deriveFont(20.0f);


来源:https://stackoverflow.com/questions/6101886/changing-font-size-in-java

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