Class PrintUtils

java.lang.Object
edu.cnu.mdi.util.PrintUtils
All Implemented Interfaces:
Printable

public final class PrintUtils extends Object implements Printable
Prints Swing components either directly or from an EDT-created snapshot.
  • Constructor Details

    • PrintUtils

      public PrintUtils(Component componentToBePrinted)
      Convenience constructor with default settings: fitToPage=true, centerOnPage=true, allowUpscale=false
      Parameters:
      componentToBePrinted - component to print
    • PrintUtils

      public PrintUtils(Component componentToBePrinted, boolean fitToPage, boolean centerOnPage, boolean allowUpscale)
      Full constructor with behavior knobs:
      Parameters:
      componentToBePrinted - component to print
      fitToPage - if true, scale to fit imageable area
      centerOnPage - if true, center within imageable area (after scaling)
      allowUpscale - if false, scale will never exceed 1.0 (no enlarging)
  • Method Details

    • printComponent

      public static void printComponent(Component c)
      Convenience method to print a component with default settings:
      Parameters:
      c - the component to print (must have non-zero size)
    • print

      public void print()
      Show print dialog and print if user confirms.
    • print

      public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException
      Specified by:
      print in interface Printable
      Throws:
      PrinterException
    • printComponentAsImage

      public static void printComponentAsImage(Component c)
      Capture a component on the EDT and print the resulting image.
      Parameters:
      c - component to capture and print