-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
tiger
-
x86
-
windows_2000
Name: jk109818 Date: 05/17/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :Microsoft Windows 2000
[Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
When you create an HTMLDocument it starts out with a
paragraph tag <p>. The impact of this is that any JEditor
pane whose document is an HTMLDocument (an hence uses
HTMLEditorKit) will have a blank line at the top of the
page. This is not always desirable. For some editor panes
it's desirable to not have a blank line.
For example the following program creates a window with one
JTextPane that uses the default style document and one that
uses an HTMLDocument. When you run the program you will
note that the non html textpane is tall enough to fit one
line of text where the html textpane is more like two lines
because it actually has a paragraph tag even though no tag
was inserted into the document.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the program above.
2. Note the difference in height between the two textpanes
created, one a non html textpane and the other an html text
pane.
EXPECTED VERSUS ACTUAL BEHAVIOR :
The html window should not be two lines of text in height.
Note also that you cannot type into the top line or delete
it.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.text.html.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
public class HTMLParagraphBug{
public static void main(String[] args) {
try {
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new BorderLayout());
frame.setBackground(Color.lightGray);
JTextPane pane = new JTextPane();
HTMLEditorKit kit = new HTMLEditorKit();
pane.setEditorKit(kit);
pane.setBackground(Color.lightGray);
pane.setBorder(new EtchedBorder());
JTextPane paneltop = new JTextPane();
paneltop.setBackground(Color.lightGray);
paneltop.setBorder(new EtchedBorder());
frame.getContentPane().add(BorderLayout.NORTH, paneltop);
frame.getContentPane().add(BorderLayout.CENTER, pane );
frame.addWindowListener(new AppCloser());
frame.pack();
frame.show();
} catch (Throwable t) {
System.out.println("uncaught exception: " + t);
t.printStackTrace();
}
}
protected static final class AppCloser extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Add the following lines of code:
Document doc = textpane.getDocument();
Element html =
doc.getDefaultRootElement();
Element body = html.getElement(0);
HTMLDocument.BlockElement paragraph =
(HTMLDocument.BlockElement)body.getElement(0);
try{
doc.setOuterHTML(paragraph, "<DIV></DIV>");
}
catch(Exception e)
{
e.printStackTrace();
}
(Review ID: 146310)
======================================================================