close javafx login window after successfull login -


i have create javafx login window after log in main window login window closed.

i use platform.exit(); exit entire application instead of login window.

i can't access stage controller class. using closelogin() method below doesn't work me. logincontroller class:

public class logincontroller implements initializable {      @fxml     private textfield txt_username;     @fxml     private passwordfield txt_password;     @fxml     private button btn_login;     @fxml     private button btn_cancel;     stage stage1 = null;      /**      * initializes controller class.      */     @fxml     private void btn_login(actionevent event) throws ioexception, exception {         parent root = fxmlloader.load(getclass().getresource("library.fxml"));         stage page1stage = new stage();         page1stage.setresizable(false);         page1stage.settitle("main form ");         scene scene = new scene(root);         page1stage.setscene(scene);         /*           codes           */         page1stage.show();         closelogin();     }      public void closelogin() {         stage1 = (stage) stage1.getscene().getwindow();         stage1.close();     }      @fxml     public void cancelbuttonaction() {         platform.exit();     }      @override     public void initialize(url url, resourcebundle rb) {         // todo     }  } 

use close() of stage. platform.exit terminate javafx application.

loginwindow.close(); 

where loginwindow stage want close.

update

you can trying instance of stage stage1 has not yet been initialized. using

stage1.getscene().getwindow(); 

should throw nullpointerexception.

try getting instance of window textfield or button, present on scene graph.

public void closelogin() {      stage1 = (stage) btn_login.getscene().getwindow();      stage1.close(); } 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -