I have three text fields displayed, and I want to change the second one, see the result on the display (so wait a couple of seconds), then change the third one, and see the result on the display. Instead, I only see the result of both changes on the display (with no pause inbetween).
import javafx.application.Application;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.animation.PauseTransition;
import javafx.util.Duration;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
public class TestApp extends Application
{
private Text tone = new Text("one");
private Text ttwo = new Text("two");
private Text tthree = new Text("three");
private void process()
{
PauseTransition pauseTransition = new PauseTransition(Duration.seconds(2));
pauseTransition.setOnFinished(event -> ttwo.setText("four"));
pauseTransition.play();
pauseTransition = new PauseTransition(Duration.seconds(2));
pauseTransition.setOnFinished(event -> tthree.setText("five"));
pauseTransition.play();
} // end of method "process"
@Override
public void start(Stage stage)
{
VBox vboxRoot = new VBox();
vboxRoot.getChildren().add(tone);
vboxRoot.getChildren().add(ttwo);
vboxRoot.getChildren().add(tthree);
Scene myScene = new Scene(vboxRoot,350,350);
stage.setScene(myScene);
stage.setTitle("Test");
stage.show();
process();
} // end of method "start"
} // end of class "TestApp"
So initially
one
two
three
is displayed; followed by
one
four
five
What I want to see is
one
four
three
a pause and then
one
four
five
I'm not sure if its a typo if your What I want to see is
but if its not the reason you are getting
one
two
three
to initially display is because thats what you have them set as and in this piece of code below you setup 2 PauseTransition
s that both have a 2 second wait before changing the text
private void process()
{
PauseTransition pauseTransition = new PauseTransition(Duration.seconds(2));
pauseTransition.setOnFinished(event -> ttwo.setText("four"));
pauseTransition.play();
pauseTransition = new PauseTransition(Duration.seconds(2));
pauseTransition.setOnFinished(event -> tthree.setText("five"));
pauseTransition.play();
}
To fix this you can do a few things such as
ttwo.setText("four");
at the start of your process()
methodAfter doing that you get the starting result of
one
four
three
and after the pause transition finishes 2 seconds later you will see
one
four
five
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