2

I am working on Java GUI I've got method (standardLoginScreen) which initialize Login screen, method is called by different controller.

Login screen has submit button which is handled by handleSubmitButton. I am struggling with closing Login screen using submit button.

I have tried various combinations but nothing seems to be working. Please share your thoughts.

public class StandardController {

    public Button submitButton;
    public TextField textField;
    public PasswordField passwordField;

    //Call Standard Login screen
    public void standardLoginSceen() throws IOException {

       Stage standardStage = new Stage();
       standardStage.setTitle("Standard Login Screen");
        Parent root = FXMLLoader.load(getClass().getResource("StandardSignGui.fxml"));
        standardStage.initModality(Modality.APPLICATION_MODAL);
        standardStage.setScene(new Scene(root));
        standardStage.show();
    }

    //Handles Submit button
    public void handleSubmitButton() throws IOException {

        //Closing standardStage

    }
  }
}

1 Answers1

1

This is solution which I found in different thread :

close fxml window by code, javafx

    @FXML private javafx.scene.control.Button closeButton;

@FXML
private void closeButtonAction(){
    // get a handle to the stage
    Stage stage = (Stage) closeButton.getScene().getWindow();
    // do what you have to do
    stage.close();
}