Make portion of a text bold in a JavaFx Label or Text

It is possible to use TextFlow container from JavaFX8.
Then you can easily add differently styled Text nodes inside it.

TextFlow flow = new TextFlow();

Text text1=new Text("Some Text");
text1.setStyle("-fx-font-weight: bold");

Text text2=new Text("Some Text");
text2.setStyle("-fx-font-weight: regular");

flow.getChildren().addAll(text1, text2);

TextFlow container will automatically wrap content Text nodes.

enter image description here

Leave a Comment