JDK-8292276 : Add named colors from CSS Color Module Level 4
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8,11,17,18,19,20
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2022-08-11
  • Updated: 2023-11-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
CSR :  
Description
A DESCRIPTION OF THE PROBLEM :
In the Swing HTML package, we can't use most of the named colors from the CSS 4 Level recommendation. https://www.w3.org/TR/2022/CR-css-color-4-20220705/#named-colors.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Test the provided program with :
- JDK without patch.
- JDK patched (PR https://github.com/openjdk/jdk/pull/9825)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
With the patch, the two texts must be the same color cyan.
ACTUAL -
Without the patch, the first text is blakck, the second text is cyan.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;

public class CSSNamedColorTest{
  public static void main(String[] args){
    new CSSNamedColorTest();
  }
  
  public CSSNamedColorTest(){
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        JEditorPane jEditorPane = new JEditorPane();
        jEditorPane.setEditable(false);
        JScrollPane scrollPane = new JScrollPane(jEditorPane);
        HTMLEditorKit kit = new HTMLEditorKit();
        jEditorPane.setEditorKit(kit);
        StyleSheet styleSheet = kit.getStyleSheet();
        styleSheet.addRule("body {color: #000; font-family:times; margin: 4px; }");
        styleSheet.addRule("#rgb {color: Cyan; font-family:times; margin: 4px; }");
        styleSheet.addRule("#nam {color: #00ffff;}");
        styleSheet.addRule("pre {font : 10px monaco; color : black; background-color : #fafafa; }");
        String htmlString = """
                            <html>
                               <body>
                                  <h1 id="rgb">Welcome ! using named cyan color</h1>
                                  <h1 id="nam">Welcome with hex cyan coded</h2>
                                  <p>The two lines must have the same color.</p>
                                  <p>First Welcome in black means that the named color is not implemented.</p>
                               </body>
                            </html>
                            """;
        Document doc = kit.createDefaultDocument();
        jEditorPane.setDocument(doc);
        jEditorPane.setText(htmlString);
        JFrame jf = new JFrame("CSS named colors Test");
        jf.getContentPane().add(scrollPane, BorderLayout.CENTER);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setSize(new Dimension(600,400));
        jf.setLocationRelativeTo(null);
        jf.setVisible(true);
      }
    });
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Other suggestions are available at https://github.com/scientificware/jdk/issues/12

FREQUENCY : always



Comments
A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/9825 Date: 2022-08-10 20:00:29 +0000
12-08-2022

Checked with attached testcase in Windows 10, Issue is reproducible, the first sentence is black, the second sentence is cyan. <attached screenshot> Test Result ========= 8: Fail 8u341: Fail 11: Fail 11.0.16: Fail 17: Fail 18: Fail 19ea35: Fail 20ea10: Fail
12-08-2022