I'm trying to create a TabPane which is driven by ...
# tornadofx
m
I'm trying to create a TabPane which is driven by an observable list. It manages a view for each item in the list. Should I create it as a subclass of TabPane? as a Fragment? How do you create custom panes in tornadofx?
m
you mean the tabs are driven by an observable list?
m
Yes, I implemented it as a fragment. That is not the problem. But I feel I should be able to use it as another pane, instead. I was wondering how to do that. Usually, in other GUI frameworks, that's very simple.
m
the tabpane has an observable list of tabs that you can bind to
Copy code
val myTabs = mutableListOf<Tab>().asObservable()
tabpane {
    Bindings.bindContent(tabs, myTabs)
}
any time "myTabs" change, the tabpane will be updated to relfect what's in "myTabs"
if you have an observable list of something else that you want to create tabs from, you can do that too
Copy code
val tabNames = mutableListOf<String>().asObservable()
        tabpane {
            tabs.bind(tabNames) {
                Tab(it)
            }
        }
there are a number of options with bindings
bindings are very powerful but can be tricky
m
Thanks, Marshall! That is very useful. I was duplicating that mechanism.
m
no problem