I have a button that when pressed should open a new scene from an fxml file:
@FXML
private void button(ActionEvent event) throws IOException {
navigation.getChildren().clear();
AnchorPane newPane = FXMLLoader.load(getClass().getResource("Controller.fxml"));
this.navigation.getChildren().setAll(newPane);
}
but what's happening is that the code within the controller of the fxml file is performed first before the scene is actually opened.
So in the controller class I have:
public void initialize(URL url, ResourceBundle rb) {
try {
method1();
Thread.sleep(2000);
method2();
Thread.sleep(2000);
method3();
} catch (InterruptedException ex) {
Logger.getLogger(ScanningController.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void method1(){
System.out.println("method1");
progressBar.setProgress(0.33);
}
public void method2(){
System.out.println("method2");
progressBar.setProgress(0.66);
}
public void method3(){
System.out.println("method3");
progressBar.setProgress(1);
}
method1, method2, method3 are all performed THEN the scene is opened but I want these methods to happen while the new scene is open.
I don't know why it does this.
Any suggestions would be appreciated. Thank you.
Edit: This is just one example, it's not necessarily just for the progress bar, it's happening with all my controller classes. For example, I have a class that sends and receives bytes to an Arduino from a Raspberry Pi and the scene opens straight after the code as been implemented.