在 Java 中更改字体大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6101886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing font size in Java
提问by Stan
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.
我在 Java 中使用了我自己的自定义字体,但是我遇到了一个问题,字体大小似乎保持在 1。我尝试font.deriveFont(20.0f);
了我的 initialize 方法,但是,它没有调整大小。
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?
这是我创建字体并尝试更改大小的代码,但这不起作用。有什么帮助让它工作吗?
回答by Howard
deriveFont
returns a reference to a new font instance. Thus you need to assign it back to font, e.g.
deriveFont
返回对新字体实例的引用。因此,您需要将其分配回字体,例如
font = font.deriveFont(20.0f);