JavaFX change color of one word in a label

My solution for this was to use a TextFlow pane:

TextFlow textFlowPane = new TextFlow();
Text redText = new Text("This is red text...");
redText.setFill(Color.RED);
Text greenText = new Text("followed by green text");
greenText.setFill(Color.GREEN);
textFlowPane.getChildren().addAll(redText, greenText);

Red and green text with textFlow


Please try using Text inplace of Label for amount. I hope it will fix the issue. You can directly apply color to the Text as well.

Text amount = new Text("350");
amount.setFill(Color.RED);

Tags:

Css

Javafx