Andy, thank you for such a detailed reply.

Unfortunately, I believe this direction is misguided and should be avoided. 
That’s why I’ve added further information to JDK-8356436.

Best regards, Pavel

On 5/7/25 22:14, Andy Goryachev wrote:

> Could you please confirm whether 
RichParagraph.Builder.addWithStyleNames(String text, String... css) can also be 
used for background coloring?

No, it cannot.  This (and other methods that add a text segment), while adding 
the style names to the underlying nodes, cannot style the background.  The 
reason is these methods add the Text instances, and the Text class does not 
have the background property.  So even if your CSS style specifies the 
background properties, they will be ignored.

The highlights, on the other hand, are special shapes placed behind the text 
nodes, and these can be styled with background (though the corresponding public 
APIs are missing, JDK-8355774).  Same applies to wavy lines.

I'll try to clarify these points in https://bugs.openjdk.org/browse/JDK-8355774

-andy

*From: *openjfx-dev <openjfx-dev-r...@openjdk.org> on behalf of PavelTurk 
<pavelturk2...@gmail.com>
*Date: *Wednesday, May 7, 2025 at 11:54
*To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org>
*Subject: *Re: CodeArea: -fx-background-color doesn't work.

I've read your comments on the issue and was actually in the process of writing 
to you when I received your message.
Let me clarify a critically important point.

Currently, to style segment text using CSS style classes, we use this method:
RichParagraph.Builder.addWithStyleNames(String text, String... css) - ONE 
METHOD FOR ALL STYLE CLASSES.

If I understand correctly (and I might be wrong!), you're suggesting using a 
DIFFERENT method for background color styling:
RichParagraph.Builder#addHighlight(int start, int end, String... styles).

Could you please confirm whether RichParagraph.Builder.addWithStyleNames(String 
text, String... css) can also be used for background coloring?

For example, we know that user wants to add style classes "foo" and "bar" to a 
text from from 5 to 20. We do not know IF THESE STYLES
SET BACKGROUND COLOR. Or should we ask an user to name a class this way - 
"foo-bg"?

Best regards, Pavel

On 5/7/25 21:16, Andy Goryachev wrote:

    Thank /you/ for the feedback!

    I finally got the ticket - https://bugs.openjdk.org/browse/JDK-8356436 .  
It's a dup of https://bugs.openjdk.org/browse/JDK-8355774 , essentially.  Once 
the missing APIs are added, you'll be able to style the highlights with CSS:

    RichParagraph.Builder#addHighlight(int start, int length, String ... css)

    -andy

    P.S. In some of your code, you do css.toArray() for each paragraph.  I 
wonder if you should just create a bunch of styles statically instead - like a 
document stylesheet, since these names do not change at all.

    *From: *openjfx-dev <openjfx-dev-r...@openjdk.org> 
<mailto:openjfx-dev-r...@openjdk.org> on behalf of PavelTurk <pavelturk2...@gmail.com> 
<mailto:pavelturk2...@gmail.com>
    *Date: *Wednesday, May 7, 2025 at 10:30
    *To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org> 
<mailto:openjfx-dev@openjdk.org>
    *Subject: *Re: CodeArea: -fx-background-color doesn't work.

    Andy, thank you very much for your help!

    Best regards, Pavel

    On 5/7/25 20:29, Andy Goryachev wrote:

        This bug is still percolating through the system.  I'll respond once I 
get it.

        Thank you for all the questions and the feedback!

        -andy

        *From: *openjfx-dev <openjfx-dev-r...@openjdk.org> 
<mailto:openjfx-dev-r...@openjdk.org> on behalf of PavelTurk <pavelturk2...@gmail.com> 
<mailto:pavelturk2...@gmail.com>
        *Date: *Monday, May 5, 2025 at 14:13
        *To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org> 
<mailto:openjfx-dev@openjdk.org>
        *Subject: *Re: CodeArea: -fx-background-color doesn't work.

        No, I am afraid you misunderstood me. I am not talking about 
compatibility with a third party library.
        The "compatibility" already exists and its name is CSS. So, the only 
thing I need is to support
        '-fx-background-color' for RichParagraph segment.

        I've opened an issue today, so, when it is approved there won't be any 
questions.

        Best regards, Pavel

        On 5/6/25 00:04, Andy Goryachev wrote:

            Will not happen.  CSS compatibility with a third party library is 
not a requirement in this case.

            -andy

            *From: *openjfx-dev <openjfx-dev-r...@openjdk.org> 
<mailto:openjfx-dev-r...@openjdk.org> on behalf of PavelTurk <pavelturk2...@gmail.com> 
<mailto:pavelturk2...@gmail.com>
            *Date: *Monday, May 5, 2025 at 13:59
            *To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org> 
<mailto:openjfx-dev@openjdk.org>
            *Subject: *Re: CodeArea: -fx-background-color doesn't work.

            To be as clear as possible, here's what I need:

            .test {
            -fx-set-somehow-background-color: green;
            }

            var builder = RichParagraph.builder();
            builder.addWithStyleNames(segment, "test");

            because, in parallel for RTFX I simply use its stylesheet:

            .test {
            -rtfx-background-color: green;
            }


            So, for both code areas, I use same style classes for styling 
paragraph segments.

            Best regards, Pavel

            On 5/5/25 23:20, Andy Goryachev wrote:

                Right, the API are missing currently.  I just point out the 
fact that you must use highlights for the purpose of highlighting text range(s) 
within the paragraph, since these ranges might contain semi-transparent Nodes.  
Once JDK-8355774 is fixed you'll be able to style highlights with CSS and all 
will be well. Right?

                -andy

                *From: *openjfx-dev <openjfx-dev-r...@openjdk.org> 
<mailto:openjfx-dev-r...@openjdk.org> on behalf of PavelTurk <pavelturk2...@gmail.com> 
<mailto:pavelturk2...@gmail.com>
                *Date: *Monday, May 5, 2025 at 13:10
                *To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org> 
<mailto:openjfx-dev@openjdk.org>
                *Subject: *Re: CodeArea: -fx-background-color doesn't work.

                Andy, thank you very much for your help.

                That doesn’t work for me. As I mentioned before, I’m working 
with two CodeArea implementations - JFX and RTFX,
                and CSS is the common styling mechanism. I can’t use code for 
one and CSS for the other.

                Well, technically I could, but it just wouldn’t make any sense.

                Best regards, Pavel

                On 5/5/25 22:54, Andy Goryachev wrote:

                    You have to use highlights for that, since you can't assign 
CSS style to a part of the Text instance, and you can't set a background on it.

                    JDK-8355774 is pretty high on my list of things to do.

                    -andy

                    *From: *openjfx-dev <openjfx-dev-r...@openjdk.org> 
<mailto:openjfx-dev-r...@openjdk.org> on behalf of PavelTurk <pavelturk2...@gmail.com> 
<mailto:pavelturk2...@gmail.com>
                    *Date: *Monday, May 5, 2025 at 12:47
                    *To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org> 
<mailto:openjfx-dev@openjdk.org>
                    *Subject: *Re: CodeArea: -fx-background-color doesn't work.

                    Hello, Andy

                    Yes, I need to add a background color for a text segment 
within a paragraph using CSS.

                    I have just opened an issue with ID : 9078469.

                    Can anyone give an estimate of when this issue might be 
addressed? Background color is such a fundamental feature
                    that it's impossible to work without it.

                    Best regards, Pavel

                    On 5/5/25 22:09, Andy Goryachev wrote:

                        Dear Pavel:

                        Can you clarify what you are trying to do exactly?

                        If you are trying to add a background to a text segment 
within the paragraph (as your code seem to indicate), then the only way to do 
it is to call Builder.addHighlight().

                        If you are trying to set the background of the whole 
paragraph, you've hit another missing API similar to JDK-8355774 - there is 
currently no way to style the paragraphs via CSS. There is the 
Builder.setParagraphAttributes(StyleAttributeMap) but a CSS one is missing.

                        -andy

                        *From: *openjfx-dev <openjfx-dev-r...@openjdk.org> 
<mailto:openjfx-dev-r...@openjdk.org> on behalf of PavelTurk <pavelturk2...@gmail.com> 
<mailto:pavelturk2...@gmail.com>
                        *Date: *Saturday, May 3, 2025 at 10:07
                        *To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org> 
<mailto:openjfx-dev@openjdk.org>
                        *Subject: *CodeArea: -fx-background-color doesn't work.

                        For styling CodeArea, I use exclusively style classes, 
and this is the foundation of my entire architecture.
                        Today I tried to implement search highlighting (via 
background color), but it didn't work. Below is my test code.

                        Can anyone tell me how to set the background color 
using CSS? For example, in RichTextFX's CodeArea,
                        they have -rtfx-background-color.

                        public class JfxCodeArea extends Application {

                             @Override
                             public void start(Stage primaryStage) throws 
Exception {
                                 String text = """
                                               Lorem ipsum dolor sit amet, 
consectetur adipiscing elit, sed do eiusmod tempor incididunt
                                               ut labore et dolore magna 
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
                                               laboris nisi ut aliquip ex ea 
commodo consequat. Duis aute irure dolor in reprehenderit
                                               in voluptate velit esse cillum 
dolore eu fugiat nulla pariatur.
                                               """;

                                 String css = """
                                     .test {
                                         -fx-font-weight: bold;
                                         -fx-fill: red;
                                         -fx-background-color: green;
                                     }

                                 """;
                                 String data = "data:text/css;base64," + 
Base64.getEncoder().encodeToString(css.getBytes(StandardCharsets.UTF_8));

                                 CodeArea codeArea = new CodeArea();
                                 codeArea.getStylesheets().add(data);

                                 codeArea.setSyntaxDecorator(new 
SyntaxDecorator() {
                                     @Override
                                     public RichParagraph 
createRichParagraph(CodeTextModel model, int index) {
                                         var builder = RichParagraph.builder();
                                         
builder.addWithStyleNames(model.getPlainText(index), "test");
                                         return builder.build();
                                     }

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

                                     }
                                 });

                                 VBox.setVgrow(codeArea, Priority.ALWAYS);
                                 var button = new Button("Go!");
                                 button.setOnAction(e -> 
codeArea.setText(text));
                                 VBox root = new VBox(codeArea, button);
                                 Scene scene = new Scene(root, 600, 200);
                                 primaryStage.setScene(scene);
                                 primaryStage.show();

                             }

                             public static void main(String[] args) {
                                 launch(args);
                             }
                        }

                        Best regards, Pavel

Reply via email to