使用 javafx,我有一个按钮,在 css 属性中将 textFill 设置为白色。然后在运行时需要更改它,这在以下代码中发生:
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
public class QAButton extends Button {
public QAButton(String text) {
this.textProperty().set(text);
}
public void setAnswerVisible(Boolean vis) {
if (vis) this.setTextFill(Color.GREEN);
else this.setTextFill(Color.BLUE);
}
}
Run Code Online (Sandbox Code Playgroud)
但是它不会做任何事情,textFill 将保持白色。在运行时我可以做些什么来改变它?谢谢你。
编辑:我应该添加 css 代码:
.button {
-fx-text-fill: white;
}
Run Code Online (Sandbox Code Playgroud)
并且按钮的 id 设置为
#question {
-fx-background-color: darkblue;
-fx-background-radius: 0;
-fx-max-width: 2000px;
-fx-max-height: 200px;
-fx-min-height: 80px;
}
Run Code Online (Sandbox Code Playgroud)