Using Text Builder to create Text
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.TextBuilder;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Text Fonts");
Group g = new Group();
Scene scene = new Scene(g, 550, 250,Color.web("0x0000FF",1.0));
final Text text1 = TextBuilder.create()
.text("Hello World!")
.x(50).y(50)
.fill(Color.WHITE)
.build();
g.getChildren().add(text1);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Related examples in the same category