|
Description
|
FULL PRODUCT VERSION :
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)
FULL OPERATING SYSTEM VERSION :
Windows 98 [Version 4.10.2222]
A DESCRIPTION OF THE PROBLEM :
When using HTMLEditorKit to read HTML into a JTextPane, the
<center> tag does not work, the text stays left justified.
The <center> tag is widely used by HTML editors (e.g.
Netscape), so it's a pain not to have this work.
It does work OK if you have the JTextPane read the same HTML
from a file using:
URL url = new File(fileName).toURL();
myJTextPane.setPage(url);
Bug reports 4151101, 4220778, 4282675 says this or similar
bugs were fixed in 1.2 and 1.3.
Two other common tags <code> and <tt> also don't work. The
tag <h1 align=center> does center but the h1 part has no
effect.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Build and run the sample code provided below.
Note that I'm not using <head>, <body>, <br> tags or
separate lines just to keep it simple, but none of the
following work either:
"<html><head></head><body>This is line 1<center>This is line
2 (centered)</center>This is line 3</body></html>"
"<html><head></head><body>This is line 1<br><center>This is
line 2 (centered)</center><br>This is line 3</body></html>"
"<html>\n<head>\n</head>\n<body>\nThis is line
1\n<center>This is line 2 (centered)</center>\nThis is line
3\n</body>\n</html>\n"
"<html>\n<head>\n</head>\n<body>\nThis is line
1<br>\n<center>This is line 2 (centered)</center><br>\nThis
is line 3\n</body>\n</html>\n"
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected:
This is line 1
This is line 2 (centered)
This is line 3
Actual
This is line 1
This is line 2 (centered)
This is line 3
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
class Test {
static public void main(String args[]){
JFrame frame = new JFrame("Test");
frame.setSize(400,200);
frame.setVisible(true);
JTextPane pane = new JTextPane();
frame.getContentPane().add(pane);
setHTML(pane, "<html>This is line one<center>This is line two
(centered)</center>This is line three</html>");
frame.addWindowListener( new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e)
{System.exit(0); } } );
}
static void setHTML(JTextPane pane, String str) {
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = null;
try {
doc = new HTMLDocument();
kit.read(new StringReader(str),doc,0);
} catch(Exception e) { }
pane.setEditorKit(kit);
pane.setStyledDocument(doc);
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
The tags <div align=center> and <p align=center> do work.
(Review ID: 139031)
======================================================================
|