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