leo277
leo277

Reputation: 445

Changing colour of the text in Javafx textfield WHILE typing

i'm new to javafx. currently i'm trying to change the colour of a text INSIDE a textfield as the user is typing. I'm not trying to change the colour of the text somewhere else but in the textfield itself.

I've searched everywhere and everyone is talking about how to change the colour in another textfield, using Text object or TextFlow. But I'm trying to change the colour of a particular word when user is typing.

For example, if user type " go to school by 2pm" , i would like to change the colour of the word "by" to green (in the textfield itself when the user is typing).

is there anyway to achieve this? Or can this not be done? Thank you in advance :)

Upvotes: 0

Views: 562

Answers (1)

jewelsea
jewelsea

Reputation: 159281

You cannot change the color of an individual word in a TextField, only all words in the TextField. The closest you can do is subvert the selection highlight mechanism, but that is really a bit of a hack and isn't really applicable for your context where the user is actively typing in the TextField.

Rather than using the inbuilt TextField (which is not a good fit for your requirements), you might want to investigate alternate options such as Tomas Mikula's RichTextFX control.

Upvotes: 1

Related Questions