NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

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


  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: