JavaFx TabPane : One controller per Tab -


i'm new javafx , i'm trying have 1 controller per tab in tabpane. found answer : https://stackoverflow.com/a/19889980/393984 lead me :

main.fxml

<tabpane fx:controller="sample.controller" maxheight="-infinity" maxwidth="-infinity" minheight="-infinity" minwidth="-infinity" prefheight="400.0" prefwidth="600.0" tabclosingpolicy="unavailable" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/null">   <tabs>     <tab text="configuration">       <content>         <fx:include fx:id="mconfigtabpage" source="configtab.fxml"/>       </content>     </tab>     <tab text="todo">       <content>         <anchorpane minheight="0.0" minwidth="0.0" prefheight="180.0" prefwidth="200.0" />       </content>     </tab>   </tabs> </tabpane> 

configtab.fxml

<pane fx:controller="sample.configcontroller" maxheight="-infinity" maxwidth="-infinity" minheight="-infinity" minwidth="-infinity" prefheight="400.0" prefwidth="600.0" xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1">    <children>       <label layoutx="23.0" layouty="22.0" text="api key :" />       <textfield layoutx="95.0" layouty="18.0" fx:id="mapikey" />    </children> </pane> 

controller.java

public class controller {     private stage mstage;      @fxml     private configcontroller mconfigtabpage;      public void controller(){}      public void setstage(stage stage)     {         mstage = stage;     }      @fxml     public void initialize() {         system.out.println("controller");     } } 

configcontroller.java

public class configcontroller {     public void configcontroller(){}      @fxml     public void initialize() {         system.out.println("config controller");     } } 

my program launching if remove

@fxml private configcontroller mconfigtabpage; 

in main controller.

but add have following exception :

java.lang.illegalargumentexception: can not set sample.configcontroller field sample.controller.mconfigtabpage javafx.scene.layout.anchorpane

so i'm guessing javafx trying cast controller anchorpane , causing problem.

what should able have reference of each pane's controllers in main controller ?

if want controller of fx:id="something" append suffix controller java member field. have use:

@fxml private configcontroller mconfigtabpagecontroller; 

see reference.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

android - CoordinatorLayout, FAB and container layout conflict -