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: 4671625
Votes 0
Synopsis HTMLEditorKit <center> tag doesn't work
Category java:classes_swing
Reported Against merlin-rc1
Release Fixed
State 11-Closed, Not a Defect, bug
Priority: 4-Low
Related Bugs
Submit Date 19-APR-2002
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) 
======================================================================
Work Around
N/A
Evaluation





(  xxxxx@xxxxx  )

I think this is not a bug. The reason of such behavior is that
when the 'doc = HTMLDocument()' is called the created instance of HTMLDocument 
class
has default StyleSheet which doesn't contain HTML style sheet.
It causes that tag <center>, tag <a> and other are not displayed correctly.
The code of Test can be changed by 2 ways:
1) instead of calling 'doc = new HTMLDocument();' to make the following call:
	doc = kit.createDefaultDocument();
2) instead of calling 'doc = new HTMLDocument();' to make the following call:
	doc = new HTMLDocument(kit.getStyleSheet());

In both cases the default HTML style sheet will be created.
I propose to close this bug as NOT a bug.


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

Submitted On 17-OCT-2002
adeuxi
This is a bug, try to save the HTML document, the alignment
is not take into account. 



PLEASE NOTE: JDK6 is formerly known as Project Mustang