java JavaFX:更改文本字段中的字体和大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32624748/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 20:30:23  来源:igfitidea点击:

JavaFX: Change font and size in a TextField

javajavafxtextfield

提问by David

The default font settings in TextField depends on your Windows settings and when they are not the same I encounter display issues. So I want to set the TextField to a specific font and size but I don't know how to do it.
Could you please help me on this ?

TextField 中的默认字体设置取决于您的 Windows 设置,当它们不同时,我会遇到显示问题。所以我想将 TextField 设置为特定的字体和大小,但我不知道该怎么做。
你能帮我解决这个问题吗?

回答by Uluk Biy

Try like this way:

像这样尝试:

TextField tf = new TextField();
tf.setFont(Font.font("Verdana", FontWeight.BOLD, 70));

or for setting a custom font

或用于设置自定义字体

tf.setFont(Font.loadFont("file:resources/fonts/isadoracyr.ttf", 120));

Ref: Using Text and Text Effects in JavaFX

参考:在 JavaFX 中使用文本和文本效果