How can I add fancy JavaFX events on hidden items?
For example, I'd like to use the "Fade" effect when I show a hidden Label, triggered by button click.
How can I add the effect when the method below is called?
@FXML
private void handleButtonAction(ActionEvent event) {
label.setVisible(true);
}
Use a FadeTransition:
@FXML private Label label;
private FadeTransition fadeIn = new FadeTransition(
Duration.millis(3000)
);
public void initialize() {
fadeIn.setNode(label);
fadeIn.setFromValue(0.0);
fadeIn.setToValue(1.0);
fadeIn.setCycleCount(1);
fadeIn.setAutoReverse(false);
}
@FXML
private void handleButtonAction(ActionEvent event) {
if (!label.isVisible()) {
label.setVisible(true);
fadeIn.playFromStart();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With