Adi
Adi

Reputation: 886

How to use preferences in tornadofx.

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.

Upvotes: 2

Views: 266

Answers (2)

Vojtanos
Vojtanos

Reputation: 61

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.

Upvotes: 1

Edvin Syse
Edvin Syse

Reputation: 7297

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.

Upvotes: 2

Related Questions