Sunday, June 26, 2016

76. Chaining Effects

We can apply a number of effects to a Node. There will only be one setEffect call, but there will be setInput for each additional effect.


Here we apply PerspectiveTransorm to button with a DropShadow. This is in contrast to last example, where only PerspectiveTransform was applied.


package ex76;

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

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

        DropShadow dropShadow = new DropShadow();
        dropShadow.setOffsetX(4);
        dropShadow.setOffsetY(6);
        dropShadow.setColor(Color.PURPLE);
        
        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);
        
        perspective.setInput(dropShadow);
        
        Button button = new Button("Perspective + DropShadow");
        button.setEffect(perspective);
        
        root.getChildren().add(button);
        
        Scene scene = new Scene(root, 350, 350, Color.ROSYBROWN);
        stage.setTitle("Example 76. Chaining");
        stage.setScene(scene);
        stage.show();
    }

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

This is the output:


No comments:

Post a Comment