BindableTransition

#General

#JavaFX

JavaFX supports a lot of transition and animation classes for Node properties like the javafx.animation.ScaleTransition. But sometimes you need a special animation for that no default transition is provided by JavaFX. Currently the best pratice is to extend javafx.animation.Transition and override theĀ interpolate(double frac) method:

protected void interpolate(double frac) {
  myProperty.set(frac);
}

Because JavaFX offers PropertyBinding I created a BindableTransition which current fraction is a Property and can be bind to any other NumberProperty. Here is an example:

Button button = new Button("BindableTransition");
DropShadow shadow = DropShadowBuilder.create().build();
button.setEffect(shadow);

final Duration duration = Duration.millis(1200);
BindableTransition transition = new BindableTransition(duration);
transition.setCycleCount(1000);
transition.setAutoReverse(true);

shadow.offsetXProperty().bind(transition.fractionProperty().multiply(32));
shadow.offsetYProperty().bind(transition.fractionProperty().multiply(32));
button.translateXProperty().bind(transition.fractionProperty().multiply(-32));

transition.play();

The fractionProperty of the BindableTransition is bound to three different properties and the result will look like this:

The BindableTransition class and a demoare commited to the JFXtras project.

Hendrik Ebbers

Hendrik Ebbers is the founder of Open Elements. He is a Java champion, a member of JSR expert groups and a JavaOne rockstar. Hendrik is a member of the Eclipse JakartaEE working group (WG) and the Eclipse Adoptium WG. In addition, Hendrik Ebbers is a member of the Board of Directors of the Eclipse Foundation.

Circle Circle
logo

Open Source made right

Privacy

Privacy Policy Cookie Policy Privacy Config Impressum