简体   繁体   English

如何设置提示文本字符串的颜色、字体和大小?

[英]How do I set the colour, font and size of a prompt-text string?

I am trying to change the properties of a String made from TextField::setPromptText using JavaFX.我正在尝试使用 JavaFX 更改由TextField::setPromptText制成的字符串的属性。

This code:这段代码:

TextField shapeField = new TextField();         
shapeField.setMaxWidth(100);   
shapeField.setPromptText("Circle, Triangle, Hexagon");
             
TextField fillField = new TextField();         
fillField.setMaxWidth(100);
fillField.setPromptText("Red, Green, Grey");

Currently sets the prompt text to this:当前将提示文本设置为:

提示文字

I want to be able to make the font smaller and change the colour.我希望能够使字体更小并更改颜色。 How would I do this?我该怎么做?

For color you need: -fx-prompt-text-fill: red;对于您需要的颜色:-fx-prompt-text-fill: red; and you can change font size with but you need to add an event to check if text is empty then use your prompt text size and when not the actual size of the text (edited): -fx-font-size并且您可以更改字体大小,但您需要添加一个事件来检查文本是否为空,然后使用提示文本大小,而不是文本的实际大小(已编辑):-fx-font-size

for example:例如:

tf.setStyle("-fx-prompt-text-fill: red;\n" + "-fx-font-size: 26pt;");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM