How do you change the color of a text inside a button node?
I tried this:
btn.setStyle("-fx-text-fill: white");
But it only added color to the button.
How do you change the color of a text inside a button node?
I tried this:
btn.setStyle("-fx-text-fill: white");
But it only added color to the button.
In JavaFX there are various ways to set the color of a button's text:
From hex:
private static Button createButton() {
final Button button = new Button("red");
button.setTextFill(Color.web("#ff0000"));
return button;
}
With predefined colors:
private static Button createButton() {
final Button button = new Button("red");
button.setTextFill(Color.RED);
return button;
}
From RGB values:
private static Button createButton() {
final Button button = new Button("red");
button.setTextFill(Color.rgb(255, 0, 0));
return button;
}
From HSB values:
private static Button createButton() {
final Button button = new Button("red");
button.setTextFill(Color.hsb(0, 1, 1));
return button;
}
From color where RGB is within a range of 0.0-1.0
private static Button createButton() {
final Button button = new Button("red");
button.setTextFill(Color.color(1, 0, 0));
return button;
}
Pick whichever suits your needs