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 ()
开发者_C百科 }
stage.close(), but you would need a variable that references the original stage.
The way it worked for me:
I have the Main.fx where I instante the window I want to see first. ex:
var mainWind:MainWindow = MainWindow{ };
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;
} }
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
精彩评论