Featured Whitepapers
Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Java 2 introduces print capability to the Swing Forum

Find out how to add Java 2's print functionality to your Swing-based apps

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
The Java 2 printing APIs give applications developers the ability to add print capabilities to Java applications and signed applets. The Java 2 printing system consists of a small number of interfaces and classes that encapsulate print-related entities such as printer jobs, page formats, printable pages, and collections of printable pages.

This month, we'll add Java 2 print capabilities to our old pal, the Swing Forum. But first we'll investigate the basics of the Java 2 printing system, including its operating principles and high-level features.

Java 2 printing basics

The Java 2 printing system offers applications the ability to print AWT text and graphics to any standard printer, whether networked or local. The printing system is a "callback" system, which means the system, not the printing application, drives the print process. In practice, this means the system determines the order in which pages are printed and makes callbacks into programmer-defined objects that know how to print pages. This architecture is similar to the 1.1 delegation event model and is highly analogous to the way component painting works.

The printing system consists of two entity types: job-control entities, which control printer jobs, and document-related entities, which represent documents to be printed as well as their constituent pages. The printing API is contained in the package java.awt.print.

Note: The Java 2 printing system should not be confused with the 1.1 printing system, although it is similar in some respects.

Job-control entities

Classes PrinterJob, PageFormat, and Paper are the job-control entities responsible for printer-job management.

The PrinterJob class encapsulates a printer job. PrinterJob operations include retrieving the default page format, popping up print- and page-format dialogs, and printing the job.

The PageFormat class represents a set of page-format settings. This class provides offset- and imageable-area information for use in rendering pages.

The Paper class represents the physical properties of a piece of paper in the printer. This class is used by the system and is not necessary for applications development.

In addition to the job-control entities described above, Java 2 printing makes use of document-related entities that provide both high level and low level document printing services, which we'll look at next.

Document-related entities

Document-related entities can be classified as either high level or low level. Pageable and Book are considered high level. In contrast, Printable "page painters" are low level.

High-level document-related entities represent whole documents, such as a resume, a book, or any other collection of printable pages.

A document is a collection of pages in which each page or group of pages may have different formats. For example, a business letter might consist of a "first page" that displays letterhead and standard header information and the beginning of the letter's text. This page may be followed by a series of additional pages containing the rest of the letter's text.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • Michael's previous Swing Forum articles
  • Credits