JDK-4530474 : background-color CSS attribute in HTML font tag works in style but not class
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.1
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-11-21
  • Updated: 2017-05-16
  • Resolved: 2003-09-26
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 Availabitlity Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Description

Name: gm110360			Date: 11/21/2001


java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

In HTML font tags rendered in a JEditorPane, referencing a CSS class that
contains a background-color attribute will not display that background color.
If you put the background-color inline using style then it will work.

For example
HTML fragment:
<font class="blackwhite">Hi</font>

CSS fragment:
font.blackwhite {
  background-color:black;
  color:white;
}

The font color will be set correctly, but the background color will not. If,
instead, you change the HTML to read
<font class="blackwhite" style="background-color:black">Hi</font>
specifying the background-color attribute inline, then the background color
will be rendered correctly.

Unfortunately, I did not get the opportunity to confirm this bug on other
platforms. Note that the original example is rendered correctly in IE 5.5.

Sample program that illustrates the bug, followed by CSS file. Program displays
a simple HTML page that contains a line using the font class, a line using the
workaround inline style declaration, and a table cell showing a working
implementation of background-color in class. On my system, the first line
displays with an invisible number (white on white), the second line with a
white-on-black number, and the table as white-on-black. In IE 5.5 on my system,
the first line displays with a white-on-black number, and the rest as in the
JEditorPane.

Filename: TestCSS.java
---------------------------------------------
<code>

import javax.swing.JEditorPane;
import javax.swing.JFrame;

public class TestCSS extends JFrame {

	JEditorPane pane;

	public TestCSS(String title) {
		super(title);
		pane = new JEditorPane();
		pane.setContentType("text/html");
		pane.setEditable(false);
		getContentPane().add(pane);
	} // end constructor(String)

	protected void setText(String text) {
		pane.setText(text);
	} // end setText(String)

	private void loadPage() {
		String page =
			"<html><head>" +
			"<link rel=\"stylesheet\" type=\"text/css\" href=\"" +
			"file:///C:/java/TestCSS/stylesheet.css\">" +
			"</head>" +
			"<body>" +
			"<font class=\"blackwhite\">1. </font>" +
			"Item number 1<br>" +
			"<font class=\"blackwhite\" style=\"background-color:black;\">2. </font>" +
			"Item number 2<br>" +
			"<table><tr><td class=\"blackwhite\">Table entry</td></tr></table>" +
			"</body>" +
			"</html>";
		setText(page);
	} // end loadPage()

	public static void main(String[] args) {
		TestCSS frame = new TestCSS("Test CSS");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(250,350);
		frame.setLocation(250,250);
		frame.show();
		frame.loadPage();
		// to confirm veracity of HTML generated
		System.out.println(frame.pane.getText());
	} // end main(String[])
} // end class TestCSS


</code>
---------------------------------------------

Filename: stylesheet.css
---------------------------------------------

<code>

font.blackwhite {
background-color: #000000;
color: #FFFFFF;
}

td.blackwhite {
background-color: #000000;
color: #FFFFFF;
}

</code>
---------------------------------------------
(Review ID: 134699) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b22
2004-06-14

WORK AROUND Name: gm110360 Date: 11/21/2001 Specify the background-color attribute inline using style. This somewhat defeats the purpose of using a stylesheet, however. ======================================================================
2004-06-11

EVALUATION Name: dsR10138 Date: 06/06/2002 There was a check in javax.swing.text.LabelView.setPropertiesFromAttributes() if StyleConstants.Background attribute is defined for the view and only in this case the background color was fetched. However the background color can be set via style attribute and this case wasn't considered. The idea of the fix is to remove check if StyleConstants.Background is defined and always fetch background color. An additional check if background color attribute for this view is set in stylesheet would be too expensive. ###@###.### 2002-06-06 ====================================================================== Name: dsR10138 Date: 06/10/2002 The previous idea of a fix is incorrect. The check if StyleConstants.Background is defined in text attributes shouldn't be removed since LabelView deals with all text, not only html. We should get background color from a stylesheet in InlineView which is responsible for html. ###@###.### 2002-06-10 ======================================================================
2002-06-10