Home » openjdk-7 » javax » swing » [javadoc | source]
javax.swing
class: TablePrintable [javadoc | source]
java.lang.Object
   javax.swing.TablePrintable

All Implemented Interfaces:
    Printable

An implementation of Printable for printing JTables.

This implementation spreads table rows naturally in sequence across multiple pages, fitting as many rows as possible per page. The distribution of columns, on the other hand, is controlled by a printing mode parameter passed to the constructor. When JTable.PrintMode.NORMAL is used, the implementation handles columns in a similar manner to how it handles rows, spreading them across multiple pages (in an order consistent with the table's ComponentOrientation). When JTable.PrintMode.FIT_WIDTH is given, the implementation scales the output smaller if necessary, to ensure that all columns fit on the page. (Note that width and height are scaled equally, ensuring that the aspect ratio remains the same).

The portion of table printed on each page is headed by the appropriate section of the table's JTableHeader.

Header and footer text can be added to the output by providing MessageFormat instances to the constructor. The printing code requests Strings from the formats by calling their format method with a single parameter: an Object array containing a single element of type Integer, representing the current page number.

There are certain circumstances where this Printable cannot fit items appropriately, resulting in clipped output. These are:

It is entirely valid for a developer to wrap this Printable inside another in order to create complex reports and documents. They may even request that different pages be rendered into different sized printable areas. The implementation was designed to handle this by performing most of its calculations on the fly. However, providing different sizes works best when JTable.PrintMode.FIT_WIDTH is used, or when only the printable width is changed between pages. This is because when it is printing a set of rows in JTable.PrintMode.NORMAL and the implementation determines a need to distribute columns across pages, it assumes that all of those rows will fit on each subsequent page needed to fit the columns.

It is the responsibility of the developer to ensure that the table is not modified in any way after this Printable is created (invalid modifications include changes in: size, renderers, or underlying data). The behavior of this Printable is undefined if the table is changed at any time after creation.

Constructor:
 public TablePrintable(JTable table,
    PrintMode printMode,
    MessageFormat headerFormat,
    MessageFormat footerFormat) 
    Create a new TablePrintable for the given JTable. Header and footer text can be specified using the two MessageFormat parameters. When called upon to provide a String, each format is given the current page number.
    Parameters:
    table - the table to print
    printMode - the printing mode for this printable
    headerFormat - a MessageFormat specifying the text to be used in printing a header, or null for none
    footerFormat - a MessageFormat specifying the text to be used in printing a footer, or null for none
    Throws:
    IllegalArgumentException - if passed an invalid print mode
Method from javax.swing.TablePrintable Summary:
print
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from javax.swing.TablePrintable Detail:
 public int print(Graphics graphics,
    PageFormat pageFormat,
    int pageIndex) throws PrinterException 
    Prints the specified page of the table into the given Graphics context, in the specified format.