javafx - Access actions in embed FXML -


structure of application approximately mainapplication->superfxmlcontroller->childfxmlcontroller. every childfxml has button add 1 more child element gridpane in superfxml have defined buttonhandler method in childfxmlcontroller action should happening in superfxmlcontroller (add new row in grid). question how handle action superfxmlcontroller?

here code details: addlogrecordcontroller.java (so called "superfxmlcontroller"):

@fxml private void initialize() throws ioexception { rowindex = 0;      fxmlloader loader = new fxmlloader(getclass().getresource("recordgrid.fxml"));      maingrid.add(loader.load(), 0, rowindex++);     recordgridcontroller controller = (recordgridcontroller) loader.getcontroller();     controller.setsupercontroller(this); } ... public void addrowhandle() {     try {         fxmlloader loader = new fxmlloader(getclass().getresource("recordgrid.fxml"));          maingrid.getchildren().add(loader.load());         recordgridcontroller controller = loader.getcontroller();     } catch (ioexception e) {         e.printstacktrace();     }  } 

"recordgridcontroller" referred "childfxmlcontroller":

private addlogrecordcontroller supercontroller; ... public void setsupercontroller(addlogrecordcontroller addlogrecordcontrollerclass) {     this.supercontroller = addlogrecordcontrollerclass; } ... @fxml private void addrowhandler() {     supercontroller.addrowhandle(); } 

and result window section surrounded red child fxml should duplicated many times button add qso pressed: and result window section surrounded red child fxml should duplicated many times button add qso pressed

ok, made should plan. have add following method in supercontroller:

private void loadrecordgrid(int rowindex) {     try {         fxmlloader loader = new fxmlloader(getclass().getresource("recordgrid.fxml"));          maingrid.add(loader.load(), 0, rowindex);         recordgridcontroller controller = (recordgridcontroller) loader.getcontroller();         controller.initialize(this);     } catch (ioexception e) {         e.printstacktrace();     } } 

and method initialize this:

@fxml private void initialize() {     rowindex = 0;     loadrecordgrid(rowindex++); } 

and method addrowhandler this:

public void addrowhandle() {     loadrecordgrid(rowindex++); } 

in childcontroller:

private addlogrecordcontroller supercontroller;  @fxml public void initialize(addlogrecordcontroller supercontroller) {     this.supercontroller = supercontroller; }   @fxml private void addrowhandler() {     supercontroller.addrowhandle(); } 

do not know, maybe can done more efficient way, works now. need figure how pass values of textfields child parent , back


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -