Download the JDK
Search the Tutorials
Hide the TOC
Trail: 2D Graphics
Lesson: Printing
Printing
A Basic Printing Program
Using Print Setup Dialogs
Printing a Multiple Page Document
Working with Print Services and Attributes
Printing the Contents of a User Interface
Printing Support in Swing Components
Home Page > 2D Graphics > Printing
Printing Support in Swing Components

> The `PrintUIWindow.java` example represented in the previous section demonstrates that the printout is exactly the same you saw on the screen. This appearance seems reasonable. However, if a window is scrollable, then the contents that are currently scrolled out of view are not included in the printout. This creates a dump effect on the printer. This becomes a particular problem when printing large components such as a Swing table or text components. Components may contain many lines of text which cannot all be entirely visible on the screen. In this case, print the contents displayed by the component in a manner consistent with the screen display.

> To solve this problem, the Swing table and all text components are printing aware. The following methods directly provide the use of the Java 2D™ printing:

> - `javax.swing.JTable.print();`
> - `javax.swing.text.JTextComponent.print();`

> These methods provide a full implementation of printing for their contents. An application doesn't need directly create a `PrinterJob` object and implement the `Printable` interface. The call of these methods displays a print dialog and prints the component's data in accordance with the user's selections. There are also additional methods which provide more options.

> For more information see related articles at java.sun.com.

Previous page: Printing the Contents of a User Interface
Next page: Advanced Topics in Java2D