-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
tiger
-
x86
-
windows_2000
Name: sv35042 Date: 10/18/2002
FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
FULL OPERATING SYSTEM VERSION : 5.00.2195
A DESCRIPTION OF THE PROBLEM :
When using a DefaultStyledDocument with a non-wrapping
JEditorPane, there seems to be a maximum pixel width beyond
which text begins to line wrap and "grow" insets/margins.
This seems to occur above around 32,774 pixels in width. As
text is continually added which would logically extend
beyond this width, the line clips and wraps to the next
line, and ALL lines within the JEditorPane begin
to "squish" inward -- in other words, the JEditorPane grows
progressively larger and larger internal "margins."
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Add a JEditorPane to a JPanel and insert in a
JScrollPane (note that this turns off wordwrapping -- a
requirement for this example).
2. Create a default document for the JEditorPane --
defaults to DefaultStyledDocument
3. Insert a long text (eg. over 4600 characters when using
the default font/size on win32) into the document.
4. Set the document on the JEditorPane.
5. Display the view.
6. Start entering text at the beginning of the existing
text.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Result:
Any text which would logically continue on the same line
(i.e. without a newline) and which would extend beyond (I
think) 32774 pixels in width is wrapped to the next line,
and the margins of the JEditorPane increase progressively
depending on how much the text has gone beyond the maximum
width.
Expected Result:
I expect the text to continue horizontally without wrapping
and without "squishing" the text. Incidentally, if you run
this test without a StyledDocument, by for example using an
EditorKit on the JEditorPane which uses a PlainView, the
bug doesn't occur. The text will continue along the same
line without wrapping.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.util.Arrays;
public class JEditorPaneTest {
public static void main(String[] args) {
JFrame frame = new JFrame("JEditorPane Test");
JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKit(new StyledEditorKit());
StyledDocument doc = (StyledDocument)editorPane.getEditorKit
().createDefaultDocument();
char[] cbuf = new char[4680];
Arrays.fill(cbuf, '#');
try {
doc.insertString(doc.getLength(), new String(cbuf), null);
}
catch (BadLocationException e) {
e.printStackTrace();
}
editorPane.setDocument(doc);
System.out.println(editorPane.getPreferredSize());
JPanel panel = new JPanel();
panel.add(editorPane);
JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setPreferredSize(new Dimension(500, 100));
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.getContentPane().add(scrollPane);
frame.pack();
frame.show();
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
The only way around this bug is to either:
a) manually wrap long lines to bypass the bug.
b) don't use a StyledDocument.
(Review ID: 163614)
======================================================================