An example usage of this new function follows.
This code is from a file ToggleTest.kt. An Enum is extended to include a display label which is different than the Enum value.
enum class ToggleTestEnum(val displayLabel : String)
{ C1("Choice 1"), C2("Choice 2"), C3("Choice 3") }
class ToggleTestView : View() {
val toggleTestProp = SimpleObjectProperty <ToggleTestEnum>>()
override val root = vbox {
togglegroup {
ToggleTestEnum.values().forEach {
radiobutton(it.displayLabel, value = it)
}
bind(toggleTestProp)
}
button("Print Prop") {
setOnAction {
println("prop $toggleTestProp.value")
}
}
toggleTestProp.set(ToggleTestEnum.C2)
}
}
class ToggleTestApp : App(ToggleTestView::class)
The togglegroup() builder enumerates over the set of Enum values, creating a RadioButton. The RadioButton constructor uses the value and the Enum displayLabel (a custom field). the builder closes with binding statement linking the Enum-based property to the togglegroup control.
To demonstrate the program, there is a button which echoes the value to standard out.
No comments:
Post a Comment