Is Printing broken in Java 7.
Phil Race
philip.race at oracle.com
Mon Feb 25 16:00:56 PST 2013
Both of these are OK in JDK 8
There was a bug wrt to setting font its fixed already but in a not yet
shipping release.
http://bugs.sun.com/view_bug.do?bug_id=7183516
It'll appear in a 7update.
I think this probably covers the colour too fix but I don't immediately
know that for sure.
If you download a JDK 8 dev. build you do get both fixes.
-phil.
On 2/25/2013 11:07 AM, Abhinay Reddyreddy wrote:
> Hi,
>
> The following code works fine on my mac with Java 6 but it is broken with Java 7.
>
> import java.awt.*;
> import java.awt.print.PageFormat;
> import java.awt.print.Printable;
> import java.awt.print.PrinterException;
> import java.awt.print.PrinterJob;
> import javax.print.attribute.HashPrintRequestAttributeSet;
> import javax.print.attribute.PrintRequestAttributeSet;
> import javax.print.attribute.standard.DialogTypeSelection;
> //import sun.print.DialogTypeSelection;
> import javax.swing.*;
>
> public class TextAreaPrintingDemo extends javax.swing.JFrame {
>
> public TextAreaPrintingDemo() {
> }
> private static class TextPrintable implements Printable {
>
> @Override
> public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
> if(pageIndex > 1) {
> return NO_SUCH_PAGE;
> } else {
> Graphics2D g2d = (Graphics2D)graphics;
> g2d.setColor(Color.GREEN);
> g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
> g2d.setFont(new Font("Monaco", Font.ITALIC, 13));
> g2d.drawString("This text is being printed using JRE version: " + System.getProperty("java.version") , 30, 30);
> g2d.drawString("with java home: "+ System.getProperty("java.home") , 30, 70);
> return PAGE_EXISTS;
> }
> }
> }
>
> public static void main(String args[]) {
>
> SwingUtilities.invokeLater(new Runnable() {
> public void run() {
>
> PrinterJob job = PrinterJob.getPrinterJob();
> PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
> pras.add(DialogTypeSelection.NATIVE);
> job.printDialog(pras);
> TextPrintable myPrintable = new TextPrintable();
> job.setPrintable(myPrintable);
> try {
> job.print(pras);
> } catch(Exception e)
> {
> System.out.println("exception occured");
> }
>
> }
> });
> }
>
> }
>
> It looks like with Java 7, drawString function ignores font and color while rendering the text. I have attached the outputs for reference.
>
> Could anyone let me know if this is a known issue. If it is known, is there a bug reported and any suggested workaround ?
>
>
>
>
>
> Thanks,
> Abhinay.
More information about the macosx-port-dev
mailing list