Search code examples
javajavafxrichtextfx

How do i fix my numbers not showing when using the LineNumberFactory function in javafx?


I tried using the LineNumberFactory function to add line numbers but they only show as grayish rectangles How it looks

I tried to add the .lineno and .fold-indicator classes in my css file (like this)

.fold-indicator{
-fx-background-color:#292929;
}
.fold-indicator .lineno{
-fx-fill:#4a4a4a;
}

and change the background and text color but it didnt do anything. This is how my java code looks:

    private Node createTextAreaBox() {
 mainCodeArea = new CodeArea();
        mainCodeArea.setId("mainCodeArea");
        mainCodeArea.setParagraphGraphicFactory(LineNumberFactory.get(mainCodeArea));
 if(initialText){
            mainCodeArea.replaceText(textAreaText);
        }
        else{
            mainCodeArea.replaceText("");
        }
}

any ideas as to what could be wrong?


Solution

  • First provide css class name(styleClass="code-area") on the code area

    <CustomCodeArea fx:id="codeJsonResponse"
                    styleClass="code-area"
                    minHeight="-Infinity"
                    minWidth="-Infinity"
                    AnchorPane.bottomAnchor="0.0"
                    AnchorPane.leftAnchor="0.0"
                    AnchorPane.rightAnchor="0.0"
                    AnchorPane.topAnchor="0.0"
                    VBox.vgrow="ALWAYS"/>
    

    after that define the css like below

    .code-area .lineno {
        -fx-background-color: blue;
        -fx-text-fill: white;
    }
    

    I was testing the logic here. It worked in my local. local

    Reference:https://github.com/FXMisc/RichTextFX/issues/1124