-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.8, 1.2.2
-
generic, sparc
-
generic, solaris_2.5.1
Name: aaC67449 Date: 02/25/99
HTMLEditorKit.read(...) generates redudancent paragraph element at the
end of the Document.
See example
------------------Example-----------------------------------
import javax.swing.text.html.*;
import javax.swing.text.html.*;
import javax.swing.text.*;
import java.io.*;
public class Test {
public static void main(String argv[]) {
String test1="<!DOCTYPE HTML PUBLIC \"-//w3c//DTD html 3.2//EN\"><HTML><HEAD><TITLE>test</TITLE></HEAD><BODY><p>Test</p></BODY></HTML>";
HTMLEditorKit c= new HTMLEditorKit();
Document doc = c.createDefaultDocument();
try {
c.read(new StringReader(test1),doc,0); // prepare test document
StringWriter sw=new StringWriter();
c.write(sw,doc,0,10);
System.out.println(sw.toString());
} catch(Exception e) {
e.printStackTrace();
}
}
}
-------------------Output------------------------------------
<html>
<head>
<title>test </title>
</head>
<body>
<p>
Test
</p>
<p>
</p>
</body>
</html>
======================================================================
Reopen:
The test passed, but the problem still exists.
See a little more complex example ('HR' tag was added after paragraph).
So the redudancent paragraph element is still added, if the html text does not end by 'P' tag. See a little more complex example ('HR' tag was added after paragraph).
------------------Example-----------------------------------
import javax.swing.text.html.*;
import javax.swing.text.*;
import java.io.*;
public class Test {
public static void main(String argv[]) {
String test="<!DOCTYPE HTML PUBLIC \"-//w3c//DTD html 3.2//EN\"><HTML><HEAD><TITLE>test</TITLE></HEAD><BODY><p>Test</p><hr></BODY></HTML>";
HTMLEditorKit c= new HTMLEditorKit();
Document doc = c.createDefaultDocument();
try {
c.read(new StringReader(test),doc,0); // prepare test document
StringWriter sw=new StringWriter();
c.write(sw,doc,0,100);
System.out.println(sw.toString());
} catch(Exception e) {
e.printStackTrace();
}
}
}
-------------------Output JDK-1.3-H ------------------------------------
<html>
<head>
<title>test </title>
</head>
<body>
<p>
Test
</p>
<hr>
<p>
</p>
</body>
</html>
###@###.### 1999-06-21
Name: skT88420 Date: 06/30/99
Bug found against swing release swing-1.1.1beta2
Create a JTree, and use the new "HTML in Components" feature
to display html text in the renderer for the TreeNodes of
a standard JTree. If you use the System Look and Feel (ala
Motif or Windows), the <p> html tag is broken in the same way
that the <br> tag is broken as specified in the note inside
of the java tutorial. In other words the label doesn't
get its preferred size correctly and ends up being only 1 line
in heigth. I tried all known html tags to try to get a page
break, and none of them worked.
Also of not is that the windows look and feel uses a reverse
coloring for its tree cells when they are selected (dark purple
selection background against white text). The html version of
the renderer is broken here in that it uses black text against
the dark purple background making the label unreadable.
Here is an example program that illustrates the problem.
Just run the applet, and expose any of the leaves in the tree
to see the problem.
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.io.*;
public class Test extends JApplet {
public void init() {
String lname = UIManager.getSystemLookAndFeelClassName();
try {
UIManager.setLookAndFeel(lname);
} catch (Exception exc) {
}
DefaultMutableTreeNode top = new DefaultMutableTreeNode(
"The Java Series");
createNodes(top);
JTree tree = new JTree(top);
JScrollPane sp = new JScrollPane();
sp.setViewportView(tree);
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
getContentPane().setLayout(gridbag);
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
gridbag.setConstraints(sp, c);
getContentPane().add(sp);
}
private void createNodes(DefaultMutableTreeNode top) {
DefaultMutableTreeNode category = null;
DefaultMutableTreeNode book = null;
category = new DefaultMutableTreeNode("<html>Books for Java Programmers"
);
top.add(category);
book = new DefaultMutableTreeNode(
"<html>The Java Tutorial:<p>Object-Oriented Programming for the Inte
rnet");
category.add(book);
book = new DefaultMutableTreeNode(
"<html>The Java Tutorial Continued:<p>The Rest of the JDK");
category.add(book);
}
}
(Review ID: 85045)
======================================================================
- duplicates
-
JDK-4208257 The HTMLDocument structure has been changed in jdk1.2.2
- Closed