Class PrintUtilities

java.lang.Object
  extended byPrintUtilities
All Implemented Interfaces:
java.awt.print.Printable

public class PrintUtilities
extends java.lang.Object
implements java.awt.print.Printable

A utility class that lets you print an arbitrary component or save as an image in .jpeg or .png format.

The component has to implement the 'Display' interface.
There are only two static functions your can use. printCompent(Component) to print to paper or .ps file. printToStream(Component, Type) to save an image file (JPEG or PNG)
eg. PrintUtilities.printComponent(yourComponent) PrintUtilities.printToStream(yourComponent, "JPEG"); PrintUtilities.printToStream(yourComponent, "PNG");

7/99 Marty Hall, http://www.apl.jhu.edu/~hall/java/ May be freely used or adapted.

Author:
Lulin Song (IRI) Feb. 06, 2006 Modified from above

Field Summary
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Method Summary
static void disableDoubleBuffering(java.awt.Component c)
          The speed and quality of printing suffers dramatically if any of the containers have double buffering turned on.
static void enableDoubleBuffering(java.awt.Component c)
          Re-enables double buffering globally.
 int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int pageIndex)
          Print drawing area components to paper.
static void printComponent(java.awt.Component c)
           
static void printToStream(java.awt.Component c, java.lang.String mimeType)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

printComponent

public static void printComponent(java.awt.Component c)

printToStream

public static void printToStream(java.awt.Component c,
                                 java.lang.String mimeType)

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
Print drawing area components to paper.

Specified by:
print in interface java.awt.print.Printable

disableDoubleBuffering

public static void disableDoubleBuffering(java.awt.Component c)
The speed and quality of printing suffers dramatically if any of the containers have double buffering turned on. So this turns it off globally.


enableDoubleBuffering

public static void enableDoubleBuffering(java.awt.Component c)
Re-enables double buffering globally.