开发者

javafx close window

开发者 https://www.devze.com 2023-02-08 11:35 出处:网络
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 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 ()
开发者_C百科                }


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消