How to work with Property in JavaFX


#1
My question

Does not work trigger an event when the value is changed, why?

import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty
import javafx.fxml.*
import javafx.scene.control.*
import java.net.*
import java.util.*

class MainController : Initializable {

    @FXML
    lateinit var nameField: TextField

    //@JvmField
    internal val name: StringProperty = SimpleStringProperty("default")

    override fun initialize(location: URL?, resources: ResourceBundle?) {

        name.addListener { _ -> println("Does not work") }

        //name.set("Alfred") // ok

        nameField.textProperty().bindBidirectional(name)
    }
}

It’s to blame, it will not work, confused.


#2

Kotlin properties and JvavFX properties are two completely different things, one can not bind anything to them.You should use tornadofx to bring them together.

And please work on your english explanations. Yours look like you try to write haiku. There is a Russian section in kotlin slack channel.


#3

I use the properties of Java, sorry for my English. I do not know him.


#4

Java properties also wont work with JavaFX. You need a StringProperty object.


#5

I use StringProperty in the example, they do not have to work the way I wanted, I made a mistake.


#6

Sorry, missed that. In that case, everything should work just as in Java.


#7

Thank you for your reply.