JavaFX Text set strike through

Description

JavaFX Text set strike through

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
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//from ww w .  j  ava  2  s. c  om
  public void start(Stage primaryStage) {

    Pane pane = new Pane();
    pane.setPadding(new Insets(5, 5, 5, 5));
    Text text1 = new Text(20, 20, "demo from demo2s.com");
    text1.setFont(Font.font("Courier", FontWeight.BOLD, FontPosture.ITALIC, 15));
    pane.getChildren().add(text1);

    Text text2 = new Text(60, 60, "line 1\n line 2");
    pane.getChildren().add(text2);

    Text text3 = new Text(10, 100, "hi\ntext");
    text3.setFill(Color.RED);
    text3.setStrikethrough(true);
    pane.getChildren().add(text3);

    Scene scene = new Scene(pane);
    primaryStage.setTitle("ShowText");
    primaryStage.setScene(scene);
    primaryStage.show();
  }

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



PreviousNext

Related