I am trying to use preferences in tornadofx . but documentation has very few about it. "unresolved references" to "preferences". From where to import preferences ? Please give and clear example.
2
votes
2 Answers
2
votes
The Preferences API in JavaFX allows you store store arbitrary configuration options in an OS dependent way. It's a direct alternative to the config functionality in TornadoFX. This example retrieves and stores a value from the default Perferences node:
class UserEditor : View("User Editor") {
val name = SimpleStringProperty()
init {
preferences {
name.value = get("name", "Default Name")
}
}
override val root = form {
fieldset {
field("Name") {
textfield(name)
}
}
button("Save").action {
preferences {
put("name", name.value)
}
}
}
}
TornadoFX merely facilitates easier access to the Preferences store available to JavaFX applications. You can also pass a specific node name as parameter to the preferences function.
1
votes
Try the official guide to TornadoFX config here.
It shows an example of configuration settings applied to the user login form, communication with ViewModel, and other useful stuff.