Home > database >  How to set the size of a font from a file in Swing?
How to set the size of a font from a file in Swing?

Time:02-15

I want for my GUI to make my font bigger, as I saw it is really simple to do that with a regular font, but I didn't find anything on custom fonts from files, my current code looks like this:

InputStream is = App.class.getResourceAsStream("/mycustomfont.ttf");
try {
    assert is != null;
    font = Font.createFont(Font.TRUETYPE_FONT, is); // I get the font here but I don't have any options to change it's size
} catch (FontFormatException | IOException e) {
    e.printStackTrace();
}

CodePudding user response:

font = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(42f);

See Font.deriveFont(float) for details. In fact, always refer to the documentation before asking questions. That's what it's for.

  • Related