Сергей Владимирович
10/11/2021, 9:01 AMDon't tell me what I'm doing wrong
private val map = mapOf("1" to "one", "3" to "three", "9" to "nine")
private val observableMap: ObservableMap<String, String> = FXCollections.observableMap(map)
override val root = hbox {
textfield() {
bind(Bindings.valueAt(observableMap, "1"))
}
}
textfield - is not edited.
Bogdan
10/11/2021, 3:24 PMСергей Владимирович
10/12/2021, 10:13 AMprivate val nn = SimpleMapProperty( mutableMapOf("1" to "one", "3" to "three", "9" to "nine").toObservable())
override val root = hbox {
textfield().bind(Bindings.valueAt(nn, "1"))
}
it doesn't work that way either. I can't create an ObjectBinding for a SimpleMapProperty.
I wanted to use the key to link a text field with the mutableMapOf value. Is it possible?Bogdan
10/12/2021, 3:18 PMclass TestView() : View("Test") {
private val map = mutableMapOf("1" to "one", "3" to "three", "9" to "nine")
private val tfText = createPropertyThenBindMap("1", map)
private val tfText2 = createPropertyThenBindMap("2", map)
override val root = vbox {
prefHeight = 1000.0
textfield(tfText)
// or,
textfield {
bind(tfText2)
}
val area = textarea()
button("print map").action {
area.text = map.entries.joinToString("\n") { "${it.key}:${it.value}" }
}
}
private fun createPropertyThenBindMap(key: String, map: MutableMap<String, String>): StringProperty {
val property = stringProperty(map[key])
property.onChange { map[key] = it ?: "" }
return property
}
}
Bogdan
10/12/2021, 3:20 PMСергей Владимирович
10/14/2021, 9:17 AMclass MainView : View("Hello TornadoFX") {
private var map = mutableMapOf("Name" to "one", "Mail" to "three", "Password" to "nine")
private var mapProperty:MutableList<StringProperty> = createPropertyThenBindMap(map)
var observableMap: ObservableMap<String, String> = FXCollections.observableMap(map)
var observableList: ObservableList<StringProperty> = FXCollections.observableList(mapProperty)
private fun createPropertyThenBindMap(map: MutableMap<String, String>): MutableList<StringProperty> {
val mapProperty = mutableListOf<StringProperty>()
for (el in map) {
val property = stringProperty(map[el.key])
property.onChange { map[el.key] = it ?: "" }
mapProperty.add(property)
}
return mapProperty
}
override val root = vbox {
children.bind(observableList) {
textfield(it)
}
prefHeight = 1000.0
val area = textarea()
button("print map").action {
area.text = map.entries.joinToString("\n") { "${it.key}:${it.value}" }
}
button("Send").action {
area.text = observableMap["Name"] + ":" + observableMap["Password"]
observableMap["Name"] = "fgjfj"
}
}
init {
observableMap.addListener(MapChangeListener {
var i=0
for (el in map) {
observableList[i].value = el.value
i++
}
})
}
}
Thank you very much!!