Difference between a StyleSheet#addRule and Style#addAttribute for HTMLEditorKit

I'm trying to understand how to work with CSS styles in HTMLEditorKit context.
I know that StyleSheet#addRule let's us add CSS rules, e.g.

styleSheet.addRule("p { font-size: 10px; }");

However the naming of the method and the JavaDoc doesn't say what happens if another rule with the same selector is added, e.g.

styleSheet.addRule("p { color: red; font-size: 15px; }");

What happens here? Does the new font-size overwrite the previous one, or is it appended?
Does color end up in the same rule-set object? Or another one is created?

Also, what's up with getStyle? E.g.

styleSheet.getStyle("p")

This will return the previously added rules for p, but then what does

style.addAttribute(CSS.Attribute.FONT_SIZE, "20px")

do? Does it overwrite the previous 15px? It doesn't seem so.
I'm really confused and the documentation doesn't help at all.



Read more here: https://stackoverflow.com/questions/64900659/difference-between-a-stylesheetaddrule-and-styleaddattribute-for-htmleditorkit

Content Attribution

This content was originally published by LppEdd at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: