Let me first describe the picture below:
- There are two printed papers. The only difference between them is that few space " " characters from paper in left are replaced by dot "." character in the paper in right.
- Red line represents the left border to which the text should be aligned
- Green curve represents my intention to align all characters it connects into a single column. In fact the green curve is supposed to be a vertical line.
I want all characters highlighted by the green line to be printed in one column.
Font of a String is monospaced Courier New. However, it seems that space characters are not printed as monospaced (see 'dotted' lines vs. lines with space characters at the beginning).
To print the string I use standard Java Print Service API over JTextPane component:
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(myTextPane);
pj.print();
To my knowledge the Java Print Service API in fact calls paint() methods of myTextPane. Therefore the preview should look exactly the same as the printed version of String.
However, it doesn't. The preview does not seem to misinterpret monospaced space characters (see the last picture). The preview looks exactly as I want the text to be printed.
Any suggestions how to force JavaPrintServiceAPI to print monospaced space characters correctly?