public class

TextComponentPrintable

extends Object
implements CountingPrintable
java.lang.Object
   ↳ sun.swing.text.TextComponentPrintable

Class Overview

An implementation of Printable to print JTextComponent with the header and footer.

WARNING: this class is to be used in javax.swing.text.JTextComponent only.

The implementation creates a new JTextComponent (printShell) to print the content using the Document, EditorKit and rendering-affecting properties from the original JTextComponent.

printShell is laid out on the first print invocation.

This class can be used on any thread. Part of the implementation is executed on the EDT though.

Summary

[Expand]
Inherited Constants
From interface java.awt.print.Printable
Public Methods
int getNumberOfPages()
Returns the number of pages in this printable.
static Printable getPrintable(JTextComponent textComponent, MessageFormat headerFormat, MessageFormat footerFormat)
Returns TextComponentPrintable to print textComponent.
int print(Graphics graphics, PageFormat pf, int pageIndex)
See Printable.print for the API description.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.awt.print.Printable
From interface sun.swing.text.CountingPrintable

Public Methods

public int getNumberOfPages ()

Returns the number of pages in this printable.

This number is defined only after print returns NO_SUCH_PAGE.

Returns
  • the number of pages.

public static Printable getPrintable (JTextComponent textComponent, MessageFormat headerFormat, MessageFormat footerFormat)

Returns TextComponentPrintable to print textComponent.

Parameters
textComponent JTextComponent to print
headerFormat the page header, or null for none
footerFormat the page footer, or null for none
Returns
  • TextComponentPrintable to print textComponent

public int print (Graphics graphics, PageFormat pf, int pageIndex)

See Printable.print for the API description. There are two parts in the implementation. First part (print) is to be called on the printing thread. Second part (printOnEDT) is to be called on the EDT only. print triggers printOnEDT

Parameters
graphics the context into which the page is drawn
pf the size and orientation of the page being drawn
pageIndex the zero based index of the page to be drawn
Returns
  • PAGE_EXISTS if the page is rendered successfully or NO_SUCH_PAGE if pageIndex specifies a non-existent page.