#I want to a css transition effect on a button

1 messages · Page 1 of 1 (latest)

craggy krakenBOT
#

Helper please have a look, thanks.

dusty bluff
#
@FXML
    protected void initialize() {

        myBtn.hoverProperty().addListener((observable, oldValue, newValue) -> {
            FadeTransition fade = new FadeTransition(Duration.seconds(1));

            if (oldValue) {
                fade.setOnFinished(actionEvent -> {

                    label.setText("Not hovering");
                });
                fade.play();
            }

            if (newValue) {
                fade.setOnFinished(actionEvent -> {

                    label.setText("Hovering");
                });
                fade.play();
            }
        });
    }
craggy krakenBOT
# dusty bluff ```java @FXML protected void initialize() { myBtn.hoverProperty().a...

Detected code, here are some useful tools:

Formatted code
@FXML
protected void initialize() {
  myBtn.hoverProperty().addListener((observable, oldValue, newValue) -> {
    FadeTransition fade = new FadeTransition(Duration.seconds(1));
    if (oldValue) {
      fade.setOnFinished(actionEvent -> {
        label.setText("Not hovering");
      }
      );
      fade.play();
    }
    if (newValue) {
      fade.setOnFinished(actionEvent -> {
        label.setText("Hovering");
      }
      );
      fade.play();
    }
  }
  );
}
dusty bluff
#

I wanted to do a css transiton effect on a button

#

like a slow fade

#

but because they removed transition: 1s from the css for javafx, I need to use code (unless you know of a way)

#

my code above is me trying to use the FadeTransition, it instantly chages instead of fading like I wanted