I have a JavaFX TextField control on my FXMl that looks like this...
<TextField fx:id="input_search" onKeyPressed="#keyListener" prefHeight="25.0" prefWidth="197.0" />
I want to automatically change all characters to uppercase when the user is typing.
The code in my controller :
public void keyListener(KeyEvent event){
//maybe transform the pressed key to uppercase here...
}
There are a few ways to achieve this:
Override
replaceText()
Use
TextFormatter
This part of the answer triggers
textProperty
twice and shouldn't be used. It is only here to show the original post.Instead of using the
onKeyPressed
on your TextField, use thetextProperty()
of your TextField. Just add the following code inside theinitialize()
of the controller.