0

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 :)

leo277
  • 433
  • 2
  • 15

1 Answers1

1

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.

Community
  • 1
  • 1
jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • I can't do that? oh... ok, thank you for your reply. I was hoping it will work because i wish to let the user know that he has typed a key word by coloring that word in the textfield. But ok, thanks – leo277 Oct 10 '14 at 02:55