私はjavafxで新しく、タブパインにタブごとに1つのコントローラを用意しようとしています。 私はこの答えを見つけました:これを行うために私を導くhttps://stackoverflow.com/a/19889980/393984:JavaFx TabPane:タブあたり1つのコントローラ
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");
}
}
iはメインコントローラに
@FXML
private ConfigController mConfigTabPage;
を削除する場合マイプログラムが起動されます。
しかし、すぐに私はそれを追加すると、私は次の例外があります
java.lang.IllegalArgumentExceptionが: javafx.scene.layoutに sample.ConfigControllerフィールドsample.Controller.mConfigTabPageを設定することはできませんが。 AnchorPane
私はjavafxが私のコントローラをAnchorPaneにキャストしようとしていると思います。
メインコントローラに各ペインのコントローラの参照を持たせるにはどうすればよいですか?
[JavaFxネストされたコントローラ(FXML)]の可能な複製(http://stackoverflow.com/questions/12543487/javafx-nested-controllers-fxml-include) –
fabian