Search code examples
javajavafxjavafx-2richtextfx

RichTextFx change selected text color and line number background


I want to change selected text's color or to change highlighting color, and background in line numbers in RichTextFx, but I don't know how to do it, I need your help ! enter image description here


Solution

  • .styled-text-area .selection {
        -fx-fill: pink;
    }
    

    save this as a file say styled-text-area.css

    put this file in same package with your application class

    in your class, import this file like

    area.getStylesheets().add(getClass().getResource("styled-text-area.css").toExternalForm());
    

    this will make selection color pink

    by following here and adding related style rules in styled-text-area.css you can achieve your other needs.