3131public class TransitionPane extends StackPane {
3232
3333 private Node currentNode ;
34+ private Animation oldAnimation ;
3435
3536 public TransitionPane () {
3637 FXUtils .setOverflowHidden (this );
@@ -50,6 +51,11 @@ public final void setContent(Node newView, AnimationProducer transition, Duratio
5051
5152 public void setContent (Node newView , AnimationProducer transition ,
5253 Duration duration , Interpolator interpolator ) {
54+ if (oldAnimation != null ) {
55+ oldAnimation .stop ();
56+ oldAnimation = null ;
57+ }
58+
5359 Node previousNode = currentNode != newView && getWidth () > 0 && getHeight () > 0 ? currentNode : null ;
5460 currentNode = newView ;
5561
@@ -80,15 +86,19 @@ public void setContent(Node newView, AnimationProducer transition,
8086 previousNode ,
8187 newView ,
8288 duration , interpolator );
83- newAnimation .setOnFinished (e -> {
84- setMouseTransparent (false );
85- getChildren ().remove (previousNode );
86-
87- if (cacheHint != null ) {
88- newView .setCache (false );
89+ newAnimation .statusProperty ().addListener ((observable , oldValue , newValue ) -> {
90+ if (oldValue == Animation .Status .RUNNING && newValue != Animation .Status .RUNNING ) {
91+ setMouseTransparent (false );
92+ getChildren ().remove (previousNode );
93+
94+ if (cacheHint != null ) {
95+ newView .setCache (false );
96+ }
8997 }
9098 });
91- FXUtils .playAnimation (this , "transition_pane" , newAnimation );
99+
100+ oldAnimation = newAnimation ;
101+ newAnimation .play ();
92102 });
93103
94104 }
0 commit comments