|
Horizontal and vertical alignment
J2TablePrinter will print your JTable either left, center, or right justified horizontally on the page between the left and right margins. The default value for horizontal alignment is CENTER.
Similarly, J2TablePrinter will print your JTable either top, center, or bottom justified vertically on the page between the gap below the header and gap above the footer. The default value for vertical alignment is TOP.
setHorizontalAlignment (int horizontalAlignment)
Sets the horizontal alignment (LEFT, CENTER, RIGHT) for printing the JTable on the page.
setVerticalAlignment (int verticalAlignment)
Sets the vertical alignment (TOP, CENTER, BOTTOM) for printing the JTable on the page.
Table column headers
The Java JTable component does not automatically display (and therefore J2TablePrinter will not print) table column headers. The easiest way to get JTable to draw and print with column headers is to enclose it in a JScrollPane, which will cause it to automatically use the TableHeader information to create column headers. Alternatively, you can add column headers directly using the following code:
container.setLayout(new BorderLayout());
container.add(table.getTableHeader(), BorderLayout.NORTH);
container.add(table, BorderLayout.CENTER);
J2TablePrinter gives you additional control over whether the column headers will be replicated at the top of each new printed JTable page, or just the topmost pages (i.e., preceding row 1 on all horizontally paginated pages), or not at all. The J2TablePrinter method for controlling this is:
setColumnHeaderPrinting (int columnHeaderPrinting)
Sets whether column headers printed on ALL_PAGE, TOP_PAGES, or NO_PAGES.
With respect to the header and footer properties such as setLeftHeader that can be specified differently on the FIRST vs. REST of pages, for a JTable that paginates over multiple pages horizontally, the FIRST settings apply to all the TOP pages and the REST settings apply to the non-TOP pages.
Table row headers
The Java JTable component does not directly support row headers. However, you can set up row headers for your JTable by putting your JTable in a JScrollPane and calling the JScrollPane method setRowHeader(rowHeaders). The rowHeaders can be defined using either a JList or a single column JTable. The J2PrinterWorks sample program J2TablePrinterTestApplication contains code that implements both of these approaches. The JList approach is simpler but is limited to displaying rows of uniform height.
If row headers are defined for the JTable in this way, J2TablePrinter will print the row headers along with your JTable. J2TablePrinter lets you control whether the row headers will be replicated at the left of each new printed JTable page, or just the leftmost pages (i.e., preceding column 1 on all vertically paginated pages), or not at all. The J2TablePrinter method for controlling this is:
setRowHeaderPrinting (int rowHeaderPrinting)
Sets whether column headers printed on ALL_PAGE, LEFT_PAGES, or NO_PAGES.
Pageable properties
When J2TablePrinter is used as a Pageable, it can have its own ("local") headers & footers (left, center, and right), margins (left, right, top, and bottom), and orientation (portrait & landscape). Headers and footers can be specified as a String or a JLabel, can be different on the first page vs. the rest of the pages of the Pageable, and can include date, time, and page numbering. The methods are the same as the parallel set of methods described in the J2Printer section under "Pageable properties".
If "local" values are not specified for this J2TablePrinter instance, the "global" (overall, default) values set using the parallel J2Printer methods will be used. You can force the J2Printer "global" values to be used by calling the J2TablePrinter method(s) with the argument J2Printer.GLOBAL.
The Pageable properties of J2TablePrinter will be ignored when the J2TablePrinter is used as a Flowable. This is because in this case the Pageable is the containing J2FlowPrinter, so page properties such as headers, footers, margins, and orientation will be controlled by the J2FlowPrinter Pageable, not the J2TablePrinter used as a Flowable. Note, however, that scaling does work for J2TablePrinter used as either a Pageable or a Flowable, that is, the J2TablePrinter can appear at its own scale within an overall J2FlowPrinter sequence.
« »
|