# How to work with Property in JavaFX

**URL:** <https://discuss.kotlinlang.org/t/how-to-work-with-property-in-javafx/4254>\
**Category:** Uncategorized\
**Created:** [August 18, 2017, 9:16pm UTC](https://discuss.kotlinlang.org/t/how-to-work-with-property-in-javafx/4254 "2017-08-18T21:16:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![afonichev](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/afonichev/32/3492_2.png) [@afonichev](https://discuss.kotlinlang.org/u/afonichev)\
**Post date:** [August 18, 2017, 9:16pm UTC](https://discuss.kotlinlang.org/t/how-to-work-with-property-in-javafx/4254/1 "2017-08-18T21:16:40Z")

</div>

> **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.

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [August 19, 2017, 6:05am UTC](https://discuss.kotlinlang.org/t/how-to-work-with-property-in-javafx/4254/2 "2017-08-19T06:05:37Z")

</div>

Kotlin properties and JvavFX properties are two completely different things, one can not bind anything to them.You should use [tornadofx](https://github.com/edvin/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.

---

<div class="post-metadata">

**Author:** ![afonichev](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/afonichev/32/3492_2.png) [@afonichev](https://discuss.kotlinlang.org/u/afonichev)\
**Post date:** [August 19, 2017, 6:37am UTC](https://discuss.kotlinlang.org/t/how-to-work-with-property-in-javafx/4254/3 "2017-08-19T06:37:36Z")

</div>

> [@darksnake](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [August 19, 2017, 6:39am UTC](https://discuss.kotlinlang.org/t/how-to-work-with-property-in-javafx/4254/4 "2017-08-19T06:39:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![afonichev](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/afonichev/32/3492_2.png) [@afonichev](https://discuss.kotlinlang.org/u/afonichev)\
**Post date:** [August 19, 2017, 7:06am UTC](https://discuss.kotlinlang.org/t/how-to-work-with-property-in-javafx/4254/5 "2017-08-19T07:06:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [August 19, 2017, 7:31am UTC](https://discuss.kotlinlang.org/t/how-to-work-with-property-in-javafx/4254/6 "2017-08-19T07:31:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![afonichev](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/afonichev/32/3492_2.png) [@afonichev](https://discuss.kotlinlang.org/u/afonichev)\
**Post date:** [August 19, 2017, 7:34am UTC](https://discuss.kotlinlang.org/t/how-to-work-with-property-in-javafx/4254/7 "2017-08-19T07:34:02Z")

</div>

Thank you for your reply.
