<Swing Dev> RFR: 8256019: JLabel HTML text does not support translucent text colors

Sergey Bylokhov serb at openjdk.java.net
Thu Nov 19 19:19:05 UTC 2020


On Wed, 11 Nov 2020 08:00:09 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

> Issue is a JLabel with a translucent foreground color properly renders plain text, but with HTML text, the alpha component is discarded and the text is rendered using an opaque color.
> As per https://www.w3schools.com/cssref/func_rgba.asp, CSS supports rgba() to support alpha and render translucent text color
> but support for rgba() is not present in JDK html text rendering.
> 
> Added support for rgba() to render translucent text color.

src/java.desktop/share/classes/javax/swing/text/html/CSS.java line 1403:

> 1401:           color = parseRGB(str);
> 1402:       } else if (str.startsWith("rgba(")) {
> 1403:           color = parseRGBA(str);

Probably we need to update the spec for StyleSheet.stringToColor()

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicHTML.java line 64:

> 62:     public static View createHTMLView(JComponent c, String html) {
> 63:         BasicEditorKit kit = getFactory();
> 64:         int beginIndex = html.indexOf("rgba(");

Don't we need to implement this parsing similarly to rgb()? somewhere inside kit.createDefaultDocument() or where we parse rgb()?

-------------

PR: https://git.openjdk.java.net/jdk/pull/1158


More information about the swing-dev mailing list