Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing font size in Java

Tags:

java

fonts

size

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?

like image 305
Stan Avatar asked Dec 27 '22 20:12

Stan


1 Answers

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);
like image 149
Howard Avatar answered Jan 15 '23 09:01

Howard