JavaFX passing and getting parameters between Stage


I have two stages

Stage1 with Scene1 and own Controller1
Stage2 with another Scene2 and Controller2

From Stage1 i call Stage2 with ShowAndWait.
And set for Stage2 listener for Hiding stage.

From Stage2.Controller2 a call hide and breakpointed in

setOnHiding(new EventHandler<WindowEvent>() {
            public void handle(WindowEvent t) {

How i can passing paramers between this stages in cases:
1. stage1 pass to stage2
2. stage2 result some data params to stage1


12/16/2015 3:28:48 PM

Accepted Answer

This is my solution: I have 2 class MyStage and MyController Stage1, Stage2 should extend MyStage Controller1, Controller2 should extend MyController

Stage2 s2 = new MyStage(data);;
result = s2.getResult();

class Stage2 extends Stage{
    private FXMLLoader fxmlLoader;
    private Object data;
    private Object result;

    public Stage(Object data){ = data;
        ...//do something with data

    Object getResult(){
        return getController().getResult();

    public MyController getController() {
        return (MyController) fxmlLoader.getController();

Class MyController{
    public void initWithData(Object data){

    public Object getResult(){
    return result;

    public void setStage(Stage stage) {
            this.stage = stage;

    protected void close() {


it's general but there are some minor changes to the code when using fxml vs non-fxml. You can pass stage references to controller to close the stage from another controller. I am too sleepy now, hope there's no error. I will update later

4/29/2014 1:49:15 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow