-
Bug
-
Resolution: Not an Issue
-
P4
-
1.4.2
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.4.2_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)
Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Also Windows NT 4.0
A DESCRIPTION OF THE PROBLEM :
When editing text in a JTextPane with custom views, the text does not redraw properly with java 1.4.2 and 1.5.
It works with java 1.3.1 (not included in the regression list)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Edit text in a JTextPane with custom views.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Text is drawn correctly
ACTUAL -
Text is not drawn correctly, part of the text is missing from the end of lines, or there are gaps in the middle of lines where text should be.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.text.*;
import javax.swing.plaf.basic.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class BufferBug
{
public static void main(String[] args)
{
MyFrame f = new MyFrame ();
f.addWindowListener(new AppCloser());
f.setSize(800, 400);
f.show();
}
protected static final class AppCloser extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
}
class MyFrame extends JFrame
{
boolean useWorkAround = false;
public class MyPane extends JTextPane
{
MyPane()
{
setEditorKit(new MyEditKit());
}
public boolean isDoubleBuffered()
{
if (useWorkAround) return false;
else return super.isDoubleBuffered();
}
class MyEditKit extends StyledEditorKit implements ViewFactory
{
public ViewFactory getViewFactory()
{
return this;
}
public View create(Element elem)
{
String type = elem.getName();
if (type != null)
{
if (type.equals(AbstractDocument.ContentElementName)) return new LabelView(elem);
else if (type.equals(AbstractDocument.ParagraphElementName)) return new LeftBoxView(elem, View.X_AXIS);
else if (type.equals(AbstractDocument.SectionElementName)) return new BoxView(elem, View.Y_AXIS);
}
return null;
}
}
protected EditorKit createDefaultEditorKit()
{
return new MyEditKit();
}
}
class MyRoot extends JRootPane
{
public boolean isDoubleBuffered()
{
if (useWorkAround) return false;
else return super.isDoubleBuffered();
}
}
MyFrame()
{
if (useWorkAround) setRootPane(new MyRoot());
JTextPane editpane = new MyPane();
editpane.setText("Try selecting some text from the middle of this sentence and then press ctrl X followed by ctrl V");
setContentPane(editpane);
}
class LeftBoxView extends BoxView
{
LeftBoxView(Element e, int axis)
{
super(e,axis);
}
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements sr)
{
SizeRequirements r = super.calculateMinorAxisRequirements(axis,sr);
r.alignment = 0.0f;
r.maximum = r.preferred;
return r;
}
protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements sr)
{
SizeRequirements r = super.calculateMajorAxisRequirements(axis,sr);
r.alignment = 0.0f;
return r;
}
public void paint(Graphics g, Shape a)
{
if (useWorkAround)
{
Rectangle rect = a.getBounds();
g.setClip(rect);
}
super.paint(g,a);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
You can prevent the bug by turning off double buffering in the JTextPane and all parent components and modifying the clipping region in the Box View paint (set useWorkAround to true in the source code), but obviously doing this creates flickering of the text pane.
###@###.### 10/21/04 10:38 GMT
java version "1.4.2_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)
Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Also Windows NT 4.0
A DESCRIPTION OF THE PROBLEM :
When editing text in a JTextPane with custom views, the text does not redraw properly with java 1.4.2 and 1.5.
It works with java 1.3.1 (not included in the regression list)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Edit text in a JTextPane with custom views.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Text is drawn correctly
ACTUAL -
Text is not drawn correctly, part of the text is missing from the end of lines, or there are gaps in the middle of lines where text should be.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.text.*;
import javax.swing.plaf.basic.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class BufferBug
{
public static void main(String[] args)
{
MyFrame f = new MyFrame ();
f.addWindowListener(new AppCloser());
f.setSize(800, 400);
f.show();
}
protected static final class AppCloser extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
}
class MyFrame extends JFrame
{
boolean useWorkAround = false;
public class MyPane extends JTextPane
{
MyPane()
{
setEditorKit(new MyEditKit());
}
public boolean isDoubleBuffered()
{
if (useWorkAround) return false;
else return super.isDoubleBuffered();
}
class MyEditKit extends StyledEditorKit implements ViewFactory
{
public ViewFactory getViewFactory()
{
return this;
}
public View create(Element elem)
{
String type = elem.getName();
if (type != null)
{
if (type.equals(AbstractDocument.ContentElementName)) return new LabelView(elem);
else if (type.equals(AbstractDocument.ParagraphElementName)) return new LeftBoxView(elem, View.X_AXIS);
else if (type.equals(AbstractDocument.SectionElementName)) return new BoxView(elem, View.Y_AXIS);
}
return null;
}
}
protected EditorKit createDefaultEditorKit()
{
return new MyEditKit();
}
}
class MyRoot extends JRootPane
{
public boolean isDoubleBuffered()
{
if (useWorkAround) return false;
else return super.isDoubleBuffered();
}
}
MyFrame()
{
if (useWorkAround) setRootPane(new MyRoot());
JTextPane editpane = new MyPane();
editpane.setText("Try selecting some text from the middle of this sentence and then press ctrl X followed by ctrl V");
setContentPane(editpane);
}
class LeftBoxView extends BoxView
{
LeftBoxView(Element e, int axis)
{
super(e,axis);
}
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements sr)
{
SizeRequirements r = super.calculateMinorAxisRequirements(axis,sr);
r.alignment = 0.0f;
r.maximum = r.preferred;
return r;
}
protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements sr)
{
SizeRequirements r = super.calculateMajorAxisRequirements(axis,sr);
r.alignment = 0.0f;
return r;
}
public void paint(Graphics g, Shape a)
{
if (useWorkAround)
{
Rectangle rect = a.getBounds();
g.setClip(rect);
}
super.paint(g,a);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
You can prevent the bug by turning off double buffering in the JTextPane and all parent components and modifying the clipping region in the Box View paint (set useWorkAround to true in the source code), but obviously doing this creates flickering of the text pane.
###@###.### 10/21/04 10:38 GMT