Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

AW: printing

Hi Curtis and Yakup,

> import java.awt.print.*;
> ...
> DisplayImpl display = ...;
> PrinterJob printJob = PrinterJob.getPrinterJob();
> Printable p = display.getPrintable();
> printJob.setPrintable(p);
> if (printJob.printDialog()) printJob.print();

That's working, but only if the printJob.print() is not called from an
Event-Thread. In this case you have to enclose the printJob.print() in a
new Thread:

If (printJob.printDialog()) {
  Runnable printer = new Runnable() {
    public void run() {
      try {
        printJob.print();
      } catch (Exception exc)
        exc.printStackTrace();
      }
    }
  }
  Thread printerThread = new Thread(printer);
  printerThread.start();
}

That is because print() is calling the getImage()-method of DisplayImpl.

Cheers, Mathias


 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690