Example usage for javafx.scene Node setOpacity

List of usage examples for javafx.scene Node setOpacity

Introduction

In this page you can find the example usage for javafx.scene Node setOpacity.

Prototype

public final void setOpacity(double value) 

Source Link

Usage

From source file:com.github.vatbub.tictactoe.view.Main.java

private void fadeNode(Node node, double toValue, boolean block, Runnable onFinish) {
    guiAnimationQueue.submit(() -> {/*from ww  w.  j a v a 2  s .c  o m*/
        if (block) {
            guiAnimationQueue.setBlocked(true);
        }
        if (!node.isVisible()) {
            node.setOpacity(0);
            node.setVisible(true);
        }

        FadeTransition fadeTransition = new FadeTransition();
        fadeTransition.setNode(node);
        fadeTransition.setFromValue(node.getOpacity());
        fadeTransition.setToValue(toValue);
        fadeTransition.setDuration(Duration.seconds(animationSpeed));
        fadeTransition.setAutoReverse(false);

        fadeTransition.setOnFinished((event) -> {
            if (toValue == 0) {
                node.setEffect(null);
                node.setVisible(false);
            }
            if (block) {
                guiAnimationQueue.setBlocked(false);
            }
            if (onFinish != null) {
                onFinish.run();
            }
        });

        fadeTransition.play();
    });
}