Reputation: 35
I am working on a UI using Kotlin and TornadoFX where there is a "Main" Part, and depending on which button I press the "Main" Part of the View (currently an AnchorPane) should change like this:
I tried loading in 2 FXML documents and adding the Content to my Main-Anchorpane like this:
override val root: BorderPane by fxml("/views/MainView.fxml")
val contentContainer: AnchorPane by fxid("contentContainer")
val contentBtn1: AnchorPane by fxml("/views/MainViewProject.fxml")
val btnProject: JFXButton by fxid("btnProject")
init {
btnProject.setOnAction {
contentContainer += contentBtn1
}
}
but I get the following error:
javafx.fxml.LoadException: Controller value already specified.
Upvotes: 1
Views: 220
Reputation: 35
I solved this by creating a new View for the second FXML file:
class MainProjectView : View("My View") {
override val root: HBox by fxml()
}
Then injecting the View in my MainViewClass and adding it there:
val mainProjectView: MainProjectView by inject()
init {
mainPane += mainProjectView
}
Upvotes: 1