Function for making the code wait in javafx

102 Views Asked by At

Im new to using javaFx and programming in general so this might be a stupid question. Im trying to make a function that makes the thread wait without crashing the program which would result in something like the image above. What Im trying to achive

I have tried using thread.sleep but it crashed the gui and also something like a Timeline or PauseTransition like this:

public static void wait(int milliseconds) {
        Timeline timeline = new Timeline(new KeyFrame(Duration.millis(milliseconds)));
        timeline.setOnFinished(event -> {

        });
        timeline.play();
    }

but it doesn't work since the javafx things work on a different thread.

edit: Something to keep in mind is that there isn't something specific to do after the pause so since the function doesn't know why I need the pause for it just needs to stop the main thread for x amount of time without crashing the gui.

Example of what I mean:

System.out.println("some information");
    pause(4000);
    System.out.println("idk");
    pause(1000);
    button.setVisible(true);
    pause(5000);
    MyImage.setImage(AImage);
0

There are 0 best solutions below