Search code examples
javajavafxcontrolsinvocationtargetexceptionrichtextfx

How to add individual lines dynamically with different styles using a RichTextFX control


I am using the RichTextFX control found here https://github.com/TomasMikula/RichTextFX. I am trying to create a server Log with different lines having different styles. For example if a line is telling the user good news such as a success the line will be green, bad news red, etc.

Any and all help is appreciated.

EDIT: Have been digging for a while and found a class (InlineCssTextArea) which I think will do what I want. However I am getting a java.lang.reflect.InvocationTargetException on the line I declare and instantiate the control. I feel I might have an issue with my jar?


Solution

  • So the solution I found was to not use RichTextFX. It was too complicated a control and there was no clear documentation of it (No javadocs, sparse comments in source code). Instead I tried to use a TextFlow and style individual Text controls before adding them to the TextFlow. Like this,

    Text Stuff = new Text("Do something here");
    Stuff.setFill(Color.RED); //I am red now!
    TextFlow.getChildren().add(Stuff);
    

    I had to use Platform.runLater( () -> { }); because I was trying to manipulate the TextFlow from different threads. Hope this helped someone else out there.