Search code examples
javacssjavafxtextcolor

How do I set text color to a particular String in a TextArea?


I am developing a client for a web server application. The client has a TextArea that is displaying text both from the web server and from the client. I want the input to the client to have a particular color (in CSS) to distinguish it. The input is stored in the String userAnswer. Is it possible to create an ID that is connected with the String or any other way to do this?

Out.appendText(userAnswer + "\n");

Solution

  • Unfortunately, TextArea doesn't have that functionality (at least as of JavaFX 8). There is a GitHub project called RichTextFX which might have what you are looking for, however. It has the ability to style ranges of text with different CSS stylings.