Im making a button that switches to the next scene in Javafx, ie switching to the next FXML file.
Here is the code:
public void submitorder(ActionEvent actionEvent) throws IOException {
Customer cust = new Customer();
cust.setOrder(order);
tbl.getCustomers().add(cust);
if (tbl.getCustomers().size() == noOfDiners) {
System.out.println("if statement");
allcustomers = tbl.getCustomers();
try{
System.out.println("This prints");
Window mainWindow = btnSubmitOrder.getScene().getWindow();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("paymentScreen.fxml"));
Parent root = loader.load();
System.out.println("test");
PaymentScreenController psc = loader.getController();
psc.dataReceiver(allcustomers);
mainWindow.getScene().setRoot(root);
} catch(Exception e){
System.out.println(e.getMessage());
}
}
lvOrder.getItems().clear();
}
So that first print statement in the try method prints out so it goes into the try method but it still doesnt switch the scene. Ive used this exact code elsewhere in my program and it works so it dont know what im doing wrong.
Ive also tried not using a try method but i just get an error. In this case nothing happens
That if statement is also correct
Any help would be appreciated thanks