|
J2ListPrinter
Overview
J2ListPrinter is a Java 2 component for printing multi-page JList documents. J2ListPrinter converts any JList or JList subclass into a Java Pageable, suitable for printing by the J2Printer class (or any Java PrinterJob). It also implements Flowable for any JList, so that it may be used with J2FlowPrinter as part of a series of Flowables printed back-to-back.
J2ListPrinter Pagination
A J2ListPrinter instance will print a JList as a Pageable. J2ListPrinter paginates JList instances across multiple pages vertically, breaking the JList on row (tree node) boundaries. A JList that is too wide horizontally will be rescaled to fit the page width. The JList can be left, right, or center justified horizontally, and top, bottom, or center justified vertically. You can also specify whether to draw an outside line around the JList. The JDK 1.4/1.5 layout orientations HORIZONTAL_WRAP and VERTICAL_WRAP are also supported, permitting the printing of multiple column JList instances.
Programming
You will find it useful to begin your program with:
import com.wildcrest.j2printerworks.*;
rather than spell out the full package name for all J2PrinterWorks classes.
J2ListPrinter can instantiated with a zero-argument constructor:
J2ListPrinter listPrinter = new J2ListPrinter();
This creates a J2ListPrinter object and initializes all values to their defaults (see the J2ListPrinter Javadoc documentation ). To specify the JList to be printed by J2ListPrinter, you can use the J2ListPrinter method setList:
listPrinter.setList(yourJList);
At this point listPrinter is a Pageable suitable for printing by J2Printer.
Alternatively, you can use the single-argument J2ListPrinter constructor:
J2ListPrinter listPrinter = new J2ListPrinter(yourJList);
The following is a simple but complete Java program (J2ListPrinterSimplestTest.java ) that displays and prints a JList using J2ListPrinter:
import java.awt.*;
import javax.swing.*;
import com.wildcrest.j2printerworks.*;
class J2ListPrinterSimplestTest {
static public void main(String args[]) {
String[] data;
int num = 100;
data = new String[num];
for (int i=0; i<num; i++) {
data[i] = "This is JList item number " + (i+1);
}
JList list = new JList(data);
// can test these under JDK 1.4 or later
//list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
//list.setLayoutOrientation(JList.VERTICAL_WRAP);
list.setVisibleRowCount(35);
JFrame frame = new JFrame("J2ListPrinter test");
frame.getContentPane().add(list);
frame.pack();
frame.setVisible(true);
J2ListPrinter treePrinter = new J2ListPrinter(list);
J2Printer printer = new J2Printer();
printer.setSeparatePrintThread(false);
printer.addPageable(treePrinter);
printer.setPrintPreviewScale(1.0);
printer.printer.print();
System.exit(0);
}
}
Most of the methods of J2ListPrinter are set and get methods for controlling its property values. The full list of J2ListPrinter methods, what they do, and their default values are given in the J2ListPrinter Javadoc documentation.
General properties
Whether J2ListPrinter is used as a Pageable or a Flowable, you can control whether it is left, right, or center justified horizontally on a page, top, bottom, or center justified within the remaining space on a page, and whether to draw an outside line around the JList.
»
|