4 Answers
New AnswerYou need to learn to work with the so called styled document, it's exactly what you're looking for. It's a styled textarea, where you can style individual chars, words, or whatever you need
Don't get me wrong, but if this is your project (and I think it's pretty advanced), it's your job to find out how to realize it. Otherwise it's like asking "I want to build my own car - please explain every single step because I have no idea what to do". If you have specific (!) questions, feel free to ask.
https://www.google.com/url?sa=t&source=web&rct=j&url=https://netbeans.org/kb/73/java/editor-codereference.html&ved=2ahUKEwjQ4OzNr6TfAhWJUhUIHSsVBsgQFjAFegQIAhAB&usg=AOvVaw0kMknlKIM0iUIf_Dy214fD