Class StyleSheet

All Implemented Interfaces:
Serializable, AbstractDocument.AttributeContext

public class StyleSheet extends StyleSheet
Emulator for StyleSheet — carries author CSS from HTMLEditorKit onto the pane's rendered content.

addRule(String) is the load-bearing method; it is the second-most-used member of the whole javax.swing.text.html surface in the field, almost always in this shape:

HTMLEditorKit kit = new HTMLEditorKit();
pane.setEditorKit(kit);
kit.getStyleSheet().addRule("body { font-family: sans-serif; }");

Order does not matter. Rules added before the sheet is bound to a pane (the shape above adds them after setEditorKit, but the reverse is just as common) are held and flushed on bind, and the peer holds them again until it is attached to the DOM.

Appearance only

A rule reaches the real <h2> / <p> / <a> elements RTE renders, so tag selectors translate close to 1:1. What no rule can restore is structure Quill's model refuses — tables above all — because that is dropped as the value enters the editor, before styling could apply (SD_sjeditorpane_rte).

Deliberate divergence: the sheet is per-kit, not shared

The JDK's HTMLEditorKit.getStyleSheet() returns a static sheet shared by every kit in the JVM, so one addRule silently restyles every HTML pane in the app. We give each kit its own sheet: the sharing is a long-standing footgun rather than intent, per-pane styling is what the calling code means, and shadow-root injection is per-instance anyway. Sharing one kit across several panes still styles all of them (R_best_effort_behaviour).

What is not reproduced (R_vaadin_first)

The JDK-side rule model is not populated — getRule, getDeclaration and the AttributeSet views inherited from the JDK class read empty. The rule text is handed to the peer instead of parsed into a shadow model, per R_vaadin_first's "don't fabricate a store so a setter round-trips through its own getter"; getRules() exposes what was added for anyone who needs to see it. At-rules (@media and friends) are skipped with a WARN — the rest of the sheet still applies.
See Also:
  • Constructor Details

    • StyleSheet

      public StyleSheet()
  • Method Details

    • addRule

      public void addRule(String rule)
      Apply a CSS rule to every bound pane's content, and to any pane bound later. Accepts a single rule or a whole stylesheet's worth, as the JDK does.
      Overrides:
      addRule in class StyleSheet
    • getRules

      public List<String> getRules()
      The rule texts passed to addRule(String), in order.