Following is the code package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
Scene scene = new Scene(root);
primaryStage.setTitle("Change me");
primaryStage.setScene(scene);
primaryStage.show();
for(long i=0;i<3;i++){
primaryStage.setTitle("Change title to "+i);
try{
Thread.sleep(1000);
}
catch (Exception e){
e.printStackTrace();
}
}
}
}
The intention is to start the window and then change the title, but what happens is that first the loop executes and then window is shown.