A browser with JavaScript enabled is required for this page to operate properly.
Trail: 2D Graphics
Lesson: Printing
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:

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.


Problems with the examples? Try Compiling and Running the Examples: FAQs.
Complaints? Compliments? Suggestions? Give us your feedback.

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