I\'m building a JavaFX application with multiple Scenes. I have a problem with scope of variable when changing scenes within setOnAction event. This is my code:
This question has already been solved, but I think it's worth clarifying that your line fails because the this keyword refers to the anonymous EventHandler you are implementing. In Java, you reference the outer class instance with OuterClass.this. So OuterClass.this.getStage().allScene(createAccountPane1); will work.
If you are looking for a prettier solution, some coders like to define a local variable that points to the outer class instance:
final OuterClass self = this;
createAccountButton.setOnAction(new EventHandler(){
public void handle(ActionEvent t){
self.getStage().allScene(createAccountPane1);
}
}