United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4530474 background-color CSS attribute in HTML font tag works in style but not class
JDK-4530474 : background-color CSS attribute in HTML font tag works in style but not class

Details
Type:
Bug
Submit Date:
2001-11-21
Status:
Resolved
Updated Date:
2003-09-26
Project Name:
JDK
Resolved Date:
2003-09-26
Component:
client-libs
OS:
windows_2000
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.3.1
Fixed Versions:
5.0 (tiger)

Related Reports

Sub Tasks

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
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
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
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b22


                                     
2004-06-14



Hardware and Software, Engineered to Work Together