I abandoned the idea of โโtrying to predict or distinguish # calls from print ().
Answer to
@Atreys was promising, but the only difference I could use without mirroring or importing private sun.* sun.print.PeekGraphics that sun.print.PeekGraphics implements java.awt.image.ImageObserver , whereas sun.awt.windows.WPathGraphics no. (getClass (). getName () is considered a reflection in my book)
As a result, I used a progress bar for each individual call to Printable.print() , for example. reset progress at the beginning and advance it for each substep print. A.
So that users do not complain that the progress bar shows progress twice, I have a label that has been changed to "Pass # {k}" whenever print () is called, where {k} is the counter that increments every time.
ps The correct way to cancel a print job from Printable.print() bit more complicated. Throwing PrintAbortException does not work correctly because it ends the print () call, but the printer driver continues to work despite the fact that Printable javadoc says the following:
If the Printable object aborts the print job, it throws a PrinterException.
Instead, you should apply the Graphics () parameter of the Graphics () method as a PrintGraphics object, and then call PrintGraphics.getPrinterJob (). cancel ():
if (graphics instanceof PrinterGraphics) { PrinterGraphics pg = (PrinterGraphics) graphics; pg.getPrinterJob().cancel(); } else {
source share