java - In JavaFX & Scene Builder, how do I open a new window when clicking a button? -


i've got fxml file second window, , i'm lost here. how program open new window , fxml after press button?

this how have first window set

@override  public void start(stage primarystage) throws exception {      parent root = fxmlloader.load(getclass().getresource("main.fxml"));      scene scene = new scene(root); primarystage.setresizable(false);         primarystage.setscene(scene);      primarystage.settitle("hello world!");      primarystage.show();  }  

so copy change values new window? how link button? i've tried event handlers no avail.

if using fxml, on button there property called onaction. can find on "code" section in scene builder, or directly on .fxml file. there type name of method.

then, need create method in controller class of scene. if have not created controller scene, need set property "controller" in scene's root element, did onaction of button.

in method have created, type code open new scene, this:

fxmlloader fxmlloader = new fxmlloader(getclass().getresource("/org/yourcompanyname/yourapplicationname/layouts/nameofyourfxmlfile.fxml")); parent root = fxmlloader.load(); stage stage = new stage(); stage.initmodality(modality.application_modal); stage.setopacity(1); stage.settitle("my new stage title"); stage.setscene(new scene(root, 450, 450)); stage.showandwait(); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -