JavaFX How to - Shear Text








Question

We would like to know how to shear Text.

Answer

//w  ww .j  a v a2s. c  o m
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.transform.Shear;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage stage) {
        Group root = new Group();
        Scene scene = new Scene(root, 600, 400);
        stage.setScene(scene);
        stage.setTitle("");

        Text text = new Text("java2s.com");
        text.setX(20);
        text.setY(50);
        text.setFont(new Font(20));

        text.getTransforms().add(new Shear(-0.35, 0));
        
        root.getChildren().add(text);

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