Drawing Text - Java JavaFX

Java examples for JavaFX:Text

Introduction

Create Text nodes to be placed on the JavaFX scene graph by utilizing the javafx.scene.text.Text class.

Demo Code

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Main extends Application {

  public static void main(String[] args) {
    Application.launch(args);/* ww  w. ja va2 s  .c  o  m*/
  }

  @Override
  public void start(Stage primaryStage) {
    primaryStage.setTitle("Drawing Text");
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);
    int x = 10;
    int y = 200;
    int red = 12;
    int green = 232;
    int blue = 123;

    Text text = new Text(x, y, "test");

    int rot = 123;
    text.setFill(Color.rgb(red, green, blue, .99));
    text.setRotate(rot);
    root.getChildren().add(text);

    primaryStage.setScene(scene);
    primaryStage.show();
  }
}

Related Tutorials