Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4530474
Votes 0
Synopsis background-color CSS attribute in HTML font tag works in style but not class
Category java:classes_swing
Reported Against 1.3.1
Release Fixed 1.5(tiger)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 21-NOV-2001
Description




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) 
======================================================================
Work Around




Specify the background-color attribute inline using style. This somewhat
defeats the purpose of using a stylesheet, however.
======================================================================
Evaluation





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.

 xxxxx@xxxxx  2002-06-06


======================================================================





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.


 xxxxx@xxxxx  2002-06-10


======================================================================
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang