The
PrinterJob
class is the root of the
java.awt.print
package. To print your component, you must create a
PrinterJob
object. The
PrinterJob
class has a static method called
getPrinterJob()
.
-
Call method
getPrinterJob()
to create a printer job. -
Call the
setPrintable(Printable painter)
method to specify thePrintable
object you have implemented. -
To change the printer parameters you can open the
Print
dialog box by calling theprintDialog()
method.Print dialog box of Java SE -
If you want to change the page format, open the
Page Setup
dialog box by calling thepageDialog()
method.Page Setup Dialog Box of Java SE -
To send the printing job to the selected printers, call the
print()
method of the printer job.
See the documentation of the
PrinterJob
class for more information.