如何在 Swing 中设置文件中字体的大小?

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

我想让我的 GUI 使我的字体更大,因为我看到使用常规字体做到这一点非常简单,但我没有从文件中找到任何关于自定义字体的内容,我当前的代码如下所示:

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();
}
font = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(42f);

有关详细信息,请参阅 Font.deriveFont(float)。事实上,总是 在提问之前先参考文档。这就是它的用途。