javafx close window


Question

I have a javafx app, and I was able to spawn another window, but I can't seem to find a way to close the the window i started in. I used this to load the second window

var design = Launcher {};

                javafx.stage.Stage
                {
                    title: "Launcher"
                    scene: design.getDesignScene ()
                }
1
1
2/5/2011 5:01:23 AM

Accepted Answer

stage.close(), but you would need a variable that references the original stage.

2
2/16/2011 12:20:00 AM

The way it worked for me:

  1. I have the Main.fx where I instante the window I want to see first. ex:

    var mainWind:MainWindow = MainWindow{ };

  2. MainWindow.fx will extend CustomNode and override create() method. In the create() method I have the stage ex:

    public class MainWindow extends CustomNode{

    ...

    var stage:Stage;

    override function create():Node {

    var n:Node;
    stage = Stage {
        width: 300
        height: 180
        title: "Login"
        scene: Scene {
            content:[ userText, userTextBox, passwdText, passwdTextBox, btnsBox ]
        }
    }
    return n;
    

    } }

  3. In MainWindow.fx I have a button with an event where I close this stage and show the other one . ex:

    Button {

        text: "Login"
        font:Font{ name:"Arial" size: 12}
        layoutInfo:LayoutInfo {
            width: loginbtn_width
        }
        blocksMouse: false
       //close main window
        onMouseClicked: function(e:MouseEvent):Void { stage.close(); }
       //open the other window
        action: function(){
           // the ConnectionSettings will also extend CustomNode and will have its own stage
            var conSetWind:ConnectionSettings = ConnectionSettings{ };
        }
    

    }

Iulia


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