FULL PRODUCT VERSION :
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Printing text using JTextArea and JTextPane results in noticably uneven spacing between characters, as though the wrong kerning information is being used. Some letters have too much space after them, resulting in noticable gaps with the following letters. Other letters have too little space after them, resulting in their touching the letters that follow them.
The problem only occurs in printed output, the screen display looks fine.
The problem occurs for JTextComponent subclasses but not when printing the same strings using drawString.
This was not a problem under JDK 1.4 but appeared starting with JDK 1.5 and continues in JDK 1.6. In JDK 1.5 some more serious character spacing problems were fixed (see Bug Parade 4724061 and 4352983), but perhaps that solution introduced this new problem.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Build and run the program provided below under JDK 1.4, JDK 1.5 and JDK 1.6. Carefully compare the spacing after the letters "m", "v", and "s" in the 1.4 output versus the 1.5 and 1.6 outputs.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Spacing should be consistent, as in the 1.4 output
ACTUAL -
Spacing is uneven, as in the 1.5 and 1.6 outputs. For example, there is too much space following "m" and "s" and too little space after "v".
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;
class Test implements Printable {
static JTextArea area;
static public void main(String args[]) {
area = new JTextArea();
area.setEditable(false);
area.setText("marvelous suspicious solving");
JFrame frame = new JFrame("Printing test");
frame.getContentPane().add(area);
frame.setSize(300,200);
frame.setVisible(true);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(new Test(), job.defaultPage());
if (job.printDialog()) {
try { job.print(); }
catch (Exception e) { }
}
System.exit(0);
}
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
if (pageIndex >= 1) return Printable.NO_SUCH_PAGE;
Graphics2D g2d = (Graphics2D)g;
g2d.translate((int)pf.getImageableX(), (int)pf.getImageableY());
g2d.setClip(0, 0, (int)pf.getImageableWidth(), (int)pf.getImageableHeight());
try { area.print(g2d); }
catch (Exception e) { }
return Printable.PAGE_EXISTS;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Revert to JDK 1.4
or
Print using drawString
Release Regression From : 1.4.2_12
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.