Kelly Elton
Kelly Elton

Reputation: 4427

javafx close window

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 ()
                }

Upvotes: 1

Views: 3703

Answers (2)

Iulia
Iulia

Reputation: 31

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

Upvotes: 0

JimClarke
JimClarke

Reputation: 1409

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

Upvotes: 1

Related Questions