简体   繁体   中英

Changing font size in Java

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?

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

font = font.deriveFont(20.0f);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM