RichTextArea: How to return existing paragraphs from SyntaxDecorator?

PavelTurk pavelturk2000 at gmail.com
Mon Apr 28 23:53:53 UTC 2025


I noticed that paragraphs in CodeArea are updated too aggressively. For example, when I press a single key like '1', about 100 paragraphs get refreshed.

To improve performance, I decided to implement it this way: I store information for each paragraph indicating whether its styles are up-to-date or not.
 From SyntaxDecorator, I return the existing paragraph from the model if the styles are valid. If the styles are outdated, I build a new paragraph.

Something like this:

         codeArea.setSyntaxDecorator(new SyntaxDecorator() {
             @Override
             public RichParagraph createRichParagraph(CodeTextModel model, int index) {
                 if (paragraphStylesAreValid) {
                     return codeArea.getModel().getParagraph(index);
                 } else {
                    RichParagraph.Builder b = RichParagraph.builder();
                    ...
                    return b.build();
                 }
             }

             @Override
             public void handleChange(CodeTextModel m, TextPos start, TextPos end, int charsTop,
                     int linesAdded, int charsBottom) {

             }
         });

However, it didn't work because of this line - https://github.com/openjdk/jfx/blob/3fdd21386d6db96294fcecd80afc25d09732c067/modules/jfx.incubator.richtext/src/main/java/jfx/incubator/scene/control/richtext/model/CodeTextModel.java#L83

As I result I get StackOverflowError. Could anyone say how to do it?

Best regards, Pavel


More information about the openjfx-dev mailing list