Creating a PrintJob

The abstract java.awt.PrintJob class has a single public norags constructor, PrintJob(). However because it's an abstract class you can't instatiate it. Instead you must call the getPrintJob() method in the java.awt.Toolkit class.

public abstract PrintJob getPrintJob(Frame parent, String title, 
 Properties props)
The Frame will hold the platform specific print dialog. The title string identifies this job in the print queue and on the cover page. The props arguments is a java.awt.Properties object You can use to request different printing options on Unix. However this doesn't work on Windows, and in any case printing options are platform specific.

Print Job Dialog
A PrintJob dialog

For example:

PrintJob pj = 
 Toolkit.getDefaultToolkit().getPrintJob(new Frame(), 
 "Hello World", null);
This returns a platform specific subclass of the PrintJob class. If the user cancels the PrintJob in the dialog box, then this method should return null. (This may be a little buggy under Windows, though.)


Previous | Next | Top
Last Modified April 22, 1999
Copyright 1997, 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu