BAR
BAR

Reputation: 17091

Using TextFormatter Property

How can I use the textFormatter property to capitalize words that are typed into a textfield?

override val root = vbox {
    textfield(model.instrument) {
        textFormatter = TextFormatter (change -> change.text.toUpperCase() )
    }
}

Upvotes: 0

Views: 158

Answers (2)

Steph
Steph

Reputation: 841

TornadoFX actually has a filter builder that incorporates a text formatter:

override val root = vbox {
    textfield(model.instrument) { 
        filterInput { change ->
            change.text = change.text.toUpperCase()
            true
        }
    }
}

The builder needs a boolean to determine if the new input is valid or not so it can actually accept or reject input.

Upvotes: 2

BAR
BAR

Reputation: 17091

Pretty simple:

                textFormatter = TextFormatter<String> { change ->
                    change.text = change.text.toUpperCase()
                    change
                }

Upvotes: -1

Related Questions