Programs and Sample Code
J2PrinterWorks includes 32 sample programs with complete source
code. The source code for these applications may be freely used,
modified, incorporated, and distributed without restriction as part of
|J2PrinterWorksTestApplication||RUN ME FIRST! A comprehensive test of all the J2PrinterWorks printing components|
|StylepadPrinter||Sun's Stylepad demo program (JTextPane-based word processor) with printing added|
|J2TextPrinterTestApplication||J2TextPrinter program that reads and prints HTML, RTF, and StyledDocument files|
|J2TextPrinterHTMLFormTest||Demonstrates use of "direct print" to print user entries in HTML <form> documents|
|J2TextPrinterSimplestTest||Minimum J2TextPrinter program that prints a JTextPane (using HTML)|
|J2TablePrinterTestApplication||J2TablePrinter program that reads a file directory and prints it as a JTable|
|J2TablePrinterSimplestTest||Minimum J2TablePrinter program that prints a JTable|
|J2TreePrinterTestApplication||J2TreePrinter program that reads a file directory and prints it as a JTree|
|J2TreePrinterSimplestTest||Minimum J2TreePrinter program that prints a JTree|
|J2ListPrinterSimplestTest||Minimum J2ListPrinter program that prints a JList|
|J2PanelPrinterImageApplication||J2PanelPrinter program that reads and prints any .gif or .jpg image file|
|J2PanelPrinterGraphicsTest||Minimum J2PanelPrinter program that prints a Graphics drawing and/or Image|
|J2PanelPrinterSimplestTest||Minimum J2PanelPrinter program that prints a JLabel in a JPanel|
|J2ComponentPrinterSimplestTest||Minimum J2ComponentPrinter program that prints a Component|
|J2ComponentPrinterTestApplication||Reimplementation of J2PrinterWorksTestApplication using only J2ComponentPrinter|
|J2FlowPrinterSimplestTest||Minimum J2FlowPrinter program that prints a JTextPane, JTable, JTree, JList, and JPanel back-to-back|
that prints a typical report made up of JTextPane, JTable, JTree,
|J2Printer14PrinterSelectionTest||J2Printer14 program that lets you find and choose printers (JDK 1.4.x or later required)|
|J2Printer14CrossPlatformTest||J2Printer14 program that uses Java cross-platform printing dialogs (JDK 1.4.x or later required)|
|J2Printer14PSTest||J2Printer14 program that prints to a Postscript file (JDK 1.4.x or later required)|
|J2Printer14SimplePrintDialog||J2Printer14 program that implements a basic print dialog (JDK 1.4.x or later required)|
|J2Printer14TabbedPrintDialog||J2Printer14 program that implements a tabbed print dialog (JDK 1.4.x or later required)|
|J2Printer14PrintPlusPreviewDialog||J2Printer14 program that implements a combined print and print preview dialog (JDK 1.4.x or later required)|
|J2Printer14SimplePageSetupDialog||J2Printer14 program that implements a basic page setup dialog (JDK 1.4.x or later required)|
|J2Printer14TabbedPageSetupDialog||J2Printer14 program that implements a tabbed page setup dialog (JDK 1.4.x or later required)|
|J2PrinterWorksSimplePrintPreviewDialog||Program that implements a basic print preview dialog|
|J2PrinterWorksFullPrintPreviewDialog||Program implements the standard J2PrinterWorks full-featured print preview dialog|
prints to a PDF file + display & print any PDF file
(iText.jar and Acrobat Reader required)
|J2PrintToImageTest||Program that tests printing a page to an Image and saving Image as a .jpg file|
unsigned printing applet.
printing applet (JDK 1.4.x or later required)
that tests printing from a Java Web Start application
Installing and running sample programs
J2PrinterWorks is a Java 2 program. You must have Java 2 (JDK 1.2.x or later) installed on your system. JDK 1.4.x or later is highly recommended. You may encounter performance problems, feature limitations, and possible malfunctions when printing under JDK 1.2.x or JDK 1.3.x due to various problem present in earlier Java systems (see Known Problems section). Information is available at the Sun Java site for how to download (free) and install the latest release of Java .
All the sample programs are included in the J2PrinterWorks distribution (.zip) file. Unzip this file to create folders containing all the J2PrinterWorks sample programs.
In the top level J2PrinterWorks installation folder, you
will find a folder called samplePrograms. Inside this
folder, you will find multiple folders containing all the
J2PrinterWorks sample programs and source code files. Most
of the sample applications (all but the last three sample programs in
the above list) are double-clickable .jar files.
To run the
sample applets, double-click on the corresponding .html file.
run the J2PrinterWebStartTest, you need to build (e.g. using Ant) and
deploy to a Java-enabled web server (e.g. Tomcat). Instructions
for doing this are included in the
included in the J2PrinterWebStartTest folder and are the same as the
standard Java Web Start sample programs from Sun.
java -cp .;..\..\J2PrinterWorks.jar J2PrinterWorksTestApplication
NOTE: On Unix and Mac, the class path file
separator is colon instead of semi-colon and the path separator is
forward slash instead
of backward slash.
J2PrinterWorks supports the native and cross-platform print dialogs and the native and cross-platform page setup dialogs that are provided by Java. In addition, J2PrinterWorks contains full source code for three print dialogs, two page setup dialogs, and two print preview dialogs that may be freely modified by J2PrinterWorks developers to create dialogs suitable for their own purposes. There are seven corresponding sample programs (see above) that demonstrate the use of each of these J2PrinterWorks dialogs. The J2PrinterWorks print, page setup, and print preview dialogs source code files are:SimplePrintDialog.java - contains a basic print dialog for selecting the printer, page range, and number of copies (requires J2Printer14 and JDK 1.4 or later).
TabbedPrintDialog.java - contains a print dialog with three tabbed sections: "General" for selecting the printer, page range, and number of copies, "Page Setup" for specifying paper size, orientation, and margins, and "Headers/Footers" for specifying left, center, and right headers and footers (requires J2Printer14 and JDK 1.4 or later).PrintPlusPreviewDialog.java - contains a print dialog for selecting the printer, page range, number of copies, paper size, orientation, and margins, combined with an integrated print preview viewer (requires J2Printer14 and JDK 1.4 or later).
SimplePrintPreviewDialog.java - contains a basic print preview dialog which displays one page with minimal controls.
PrintPreviewDialog.java - contains the source code for a full-featured print preview dialog and which is the implementation of the standard J2PrinterWorks print preview dialog invoked by the J2Printer method showPrintPreviewDialog().In addition, several other J2PrinterWorks sample programs provide source code for so-called "detailed" page setup dialogs which developers may wish to use or adapt to provide control over certain J2PrinterWorks features. These page setup dialogs are not as commercial polished as the above page setup dialogs but are useful in showing how to control specific J2Printer class printing features and the features of the J2PrinterWorks printing components J2TextPrinter, J2TablePrinter, etc., including how the unique properties of these components can be displayed and modified. These special-purpose "detailed" page setup dialogs are:
J2PrinterWorksPageSetupDialog.java - contains the controls for the standard J2Printer class features including headers/footers contents, style,
and gaps, margins, print and print preview scale factors, orientation,
print thread, print dialog, number of copies, and print job name.
J2PrinterSettingsDialog.java - contains a minimum
subset of the standard J2Printer class features without features such as orientation
or margins, which therefore avoids overlap with the standard Java page setup dialogs and could be used in addition to them.
- contains the standard
J2Printer features plus controls specific to J2TextPrinter
including centering and WYSIWYG control.
J2TablePrinterPageSetupDialog.java - contains the standard
J2Printer features plus controls specific to J2TablePrinter
including centering, outside line control, column header replication
and row/column ranges.
J2TreePrinterPageSetupDialog.java - contains the standard J2Printer features plus controls specific to J2TreePrinter including centering and outside line control