configures the node to fade when it is clicked on performed the on Finished handler when the fade is complete in JavaFX. - Java JavaFX

Java examples for JavaFX:Node

Description

configures the node to fade when it is clicked on performed the on Finished handler when the fade is complete in JavaFX.

Demo Code

/*/*from  w  w  w  . j  ava2  s  . co m*/
 * Copyright (c) 2014, https://gist.github.com/jewelsea/3388637. All rights reserved.
 */
//package com.java2s;
import javafx.animation.FadeTransition;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;

import javafx.scene.Node;

import javafx.scene.input.MouseEvent;

import javafx.util.Duration;

public class Main {
    /**
     * configures the node to fade when it is clicked on performed the
     * onFinished handler when the fade is complete.
     * 
     * @param node
     *            the node
     * @param onFinished
     *            the on finished
     */
    public static void fadeOnClick(final Node node,
            final EventHandler<ActionEvent> onFinished) {
        node.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                node.setMouseTransparent(true);
                FadeTransition fade = new FadeTransition(Duration
                        .seconds(1.2), node);
                fade.setOnFinished(onFinished);
                fade.setFromValue(1);
                fade.setToValue(0);
                fade.play();
            }
        });
    }
}

Related Tutorials