I have a complicated GUI built in TornadoFX. There is a view comprised of a row of text fields and checkboxes in the middle of the main view that needs to be swappable. (The contents of the red box.)
I have a factory that generates all the textfields and checkboxes for me and returns one TornadoFX view (root contains an hbox) that I can slot into the parent TornadoFX view. The generator works, and the view is created when the program starts. The problem is that changing the combo boxes at the top is supposed to generate a new view to replace the current one in the middle. I can confirm that when I change a combobox that it's generating a new view. But I cannot swap the old view for the new one. Either nothing happens, or I lose all other elements of the view (except the original checkboxes and textfields. And the exit button, I have no idea why that stays.)
Things I have tried:
- An event bus, but while the combobox fired the event bus, nothing ever caught it and responded. (That could well be user error, I've never used event bus before.)
- Models, but again, I think I did it wrong.
- Making the center view an observable, but that just causes the problem where everything else disappears, and the view that remains is not the new one.
- Inserting the generated view straight into the parent view, sometimes does nothing, sometimes wipes out the rest of the GUI.
- placing a "container" view where I put the generated view into it so as to not disturb the rest of the parent view. That does nothing.
class ParentLayout() : View() {
var generatedView: View = viewFactory.makeOne()
val observedObject = SimpleObjectProperty(generatedView)
override val root = vbox {
add(topComboBoxes.root)
add(observedObject.view.root) // the part that should change
add(BottomHalf.root)
}
}
In the above example I'm using a vBox, but I've also tried a BorderPane with the observedObject in the center, both with and without a separate "container" view to hold the object both observed and not.
This should be far more simple than the solutions I've tried; I think I should be able to use replaceWith() and get on with my life. But again it doesn't work or causes everything else to disappear.
class ParentLayout() : View() {
var generatedView: View = viewFactory.makeOne()
override val root = borderpane {
top { add(topComboBoxes.root) }
center { add(generatedView.root) } // the part that should change
bottom { add(BottomHalf.root) }
}
fun swapCenter() {
val newGeneratedView = viewFactory.makeOne()
ParentLayout.root.center.replaceWith(newGeneratedView.root)
}
}
I don't know what I'm missing. I'm grateful for any help anyone can provide.

