JavaFX Text set font

Description

JavaFX Text set font

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Main extends Application {
  @Override// www  .j  a  va  2  s.c o  m
  public void start(Stage primaryStage) {
    FlowPane pane = new FlowPane();
    pane.setAlignment(Pos.CENTER);
    // Crate a Text and set its properties
    Text text = new Text("Java");
    text.setFont(Font.font("Times Roman", FontWeight.BOLD,
        FontPosture.ITALIC, 22));
        
    pane.getChildren().add(text);
    Scene scene = new Scene(pane, 150, 150);
    primaryStage.setTitle("java2s.com");
    primaryStage.setScene(scene);
    primaryStage.show();
  }

  public static void main(String[] args) {
    Application.launch(args);
  }
}



PreviousNext

Related