Thank you for a very good question! The short answer is yes - it is possible to implement lazy styling in CodeArea, as well as to implement styling of large documents in a reasonable fashion.
The styling is performed by the decoratorProperty of the CodeTextModel. Note: please check out the CodeAreaDemoApp in examples, along with a somewhat naïve implementation in JavaSyntaxDecorator. This is a synchronous decorator, which means it will likely be unsuitable for large models. For the large models there are a few considerations that might impact the overall design: - is it possible to style a paragraph in isolation? - does the model support concurrent access? - can the syntax be determined by backtracking from an arbitrary position, or it must be (re-)started from the beginning? One possible implementation of a SyntaxDecorator would entail having a background process which gets triggered in SyntaxDecorator::createRichParagraph(model, index). Because we don't want to hog the UI thread, it should return an unstyled RichParagraphs at first, and at the same it needs to trigger the syntax processing thread which runs from the beginning of the model. Whenever the syntax becomes available for the requested paragraphs, the decorator invokes the StyledTextModel::fireStyleChangeEvent (in the FX Application thread), which updates the view. Make sure the model supports concurrent read. Depending on the nature of the data, a number of optimizations can be made. For example, if the data has a regular structure where one does not have to restart from the beginning each time, then a synchronous implementation might work, assuming we don't need to backtrack too much to determine the syntax. Hope this helps. -andy From: openjfx-dev <openjfx-dev-r...@openjdk.org> on behalf of PavelTurk <pavelturk2...@gmail.com> Date: Thursday, April 24, 2025 at 11:19 To: openjfx-dev@openjdk.org <openjfx-dev@openjdk.org> Subject: What strategy would you recommend for styling large documents in CodeArea? Suppose we have a very large file (1,000,000+ lines). For example, it could be an XML file or a Java class written by a beginner programmer :). The question is: how should we handle styling for such large files? The simplest solution is to apply styles to all lines at once. Another option is to implement lazy styling—only styling the lines that are about to be displayed (crucially, before they are shown). Could you please clarify if lazy styling is possible in CodeArea? If yes, which API should be used for this? Or, in such cases, is a different approach recommended? Best regards, Pavel