Sunday, June 26, 2016

75. PerspectiveTransform

With PerspectiveTransform, we can set the four corners of a node to give 3D look.


Here, we apply it to a button.


package ex75;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.effect.PerspectiveTransform;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Ex75 extends Application {
    
    @Override
    public void start(Stage stage) {
        
        Group root = new Group();

        PerspectiveTransform perspective = new PerspectiveTransform();
        perspective.setUlx(10);  perspective.setUly(50);
        perspective.setLlx(10);  perspective.setLly(210);
        perspective.setUrx(300);  perspective.setUry(50);
        perspective.setLrx(300);  perspective.setLry(310);
        
        Button button = new Button("Perspective");
        button.setEffect(perspective);
        
        root.getChildren().add(button);
        
        Scene scene = new Scene(root, 350, 350, Color.ROSYBROWN);
        stage.setTitle("Example 75. Perspective");
        stage.setScene(scene);
        stage.show();
    }

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

This is the output:


No comments:

Post a Comment