java - JavaFx:What if I want to do something after initialize(),before the scene show,how can I achieve this? -
i want ,after controller's initialize() method done,but before scene show.is there method invoked before scene show?i want put code method.
fxmlloader loader = new fxmlloader(); loader.setlocation(getclass().getresource("sample.fxml")); anchorpane pane = loader.load(); scene gamescene = new scene(pane); //i load secne above,the controller,set properties,then,use properties read file before secene show. gameuicontroller controller = loader.getcontroller(); controller.setgamefileloacation("game1.txt");//i set property here.i want use read game file,and load game,set necessary ui. primarystage.setscene(gamescene);//this tow statement show scene. primarystage.show();
i can't put code initialize() method,because invoked when fxml file loads(when not yet controller).so,how can do?
thanks verymuch !
one solution find
primarystage.addeventhandler(windowevent.window_showing, new eventhandler<windowevent>() { @override public void handle(windowevent window) { //your code } });
this event occurs on window before shown.doc link
Comments
Post a Comment