Nothing happens when using java.awt.print on Mac OSX.

A

Aubrey Jones

I'm attempting to print a custom-made Swing component using the
java.awt.print protocol. It works perfectly on Linux and Windows, but
totally fails on Mac OSX. I googled, and found that Apple hasn't
implemented javax.print. But, I'm not using it, unless it's hidden
somewhere in the support classes for awt.print.

Anyway, the symptoms: neither printing nor print previews work; the
printer apparently comes out of sleep mode, but doesn't even print so
much as a blank piece of paper. Also, from tracing, I know that my
component's print() gets called.

I'm at my wit's end currently, going generally nuts over this. I'm
including my print code at the bottom. The first method handles the
printing, the second is my Printable.print() implementation (without
graphics code).

Any help would be most appreciated.

ARJ




/**
* Does printing.
* */
public void printBodyImage(){
curSession.clientName = clientField.getText();
curSession.investigatorName = investigatorField.getText();
PrinterJob printJob = PrinterJob.getPrinterJob();

//printJob.setPrintable(sessionPanel);


if (printJob.printDialog()){
try {
printJob.setPrintable(sessionPanel, printJob.defaultPage());
printJob.print();
} catch (PrinterException pe) {
RFIErrorHandler.nonfatal(pe);
}
}

}


/**
* Prints this object.
* */
public int print(Graphics g, PageFormat pageFormat, int pageIndex){
if (pageIndex > 0) {
return(NO_SUCH_PAGE);
}
Graphics2D g2d = (Graphics2D)g;
g2d.setBackground(Color.WHITE);

g2d.translate(pageFormat.getImageableX(), (pageFormat.getImageableY()
+ 72));
//These are the functions that do the actual rendering.
//They work fine on Windows and *nix, so I don't think they're
a prob.
computeScaleFactor(pageFormat.getImageableWidth(),
pageFormat.getImageableHeight() - 72);
this.drawPrint(g2d, (int) pageFormat.getImageableWidth(), (int)
pageFormat.getImageableHeight() - 72);

return (PAGE_EXISTS);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top