logo
  J2Printer known problems
logo

The Java 2 printing model was new in JDK 1.2 and there were a large number of problems there were not fixed until the JDK 1.3 release.  More problems were fixed in JDK 1.4, which also added some important new features, and JDK 1.5 and 1.6 continue these improvements.  For these reason, the use of JDK 1.4 or later, and preferably the current JDK, is strongly recommended.  This section documents problems present in Java that can impact your use of J2PrinterWorks.
 

Known Java problems affecting J2Printer

Java cross-platform print and page setup dialogs have problems
The Java cross-platform page setup dialogs have several problems on different platforms.  First, on the Macintosh the orientation choices (Portrait, Landscape, Reverse Portrait, and Reverse Landscape), Print Range, and Copies are disabled and cannot be changed (Print Range also does not work programmatically).  Secondly, on both Windows and Macintosh, if you change the "top" margin value and hit OK, the value you entered is ignored unless you first edit and change some other margin value.  The same problem occurs in the "Page Setup" tab of the Java cross-platform print dialog.  Also, tabbing between fields does not select the margins text and inserts the cursor in front of the text instead of after, and hitting the "Enter" key fails to save changes to margin values.  In addition, on the Mac there are duplicate names in the Media Size pop-up menu.  These problems have been reported to Sun and Apple, respectively.  Until they are fixed, we recommend using either the native print and page setup dialogs or the J2PrinterWorks cross-platform print and page setup dialogs.

Applets throw "NullPointerException: null pData" when using print and page setup dialogs - Bug Parade 6707276
Java applets can intermittently throw "NullPointerException: null pData" when bringing up or closing print or page setup dialogs inside Internet Explorer and other browsers on Windows.  The exception does not seem to cause any problems for printing or page setup and it appears it can be safely ignored.  Users will typically not see this message since they generally do not have the Java Console open.  The cause appears to be a window interaction problem between AWT and the browser.  It also appears that if you first click on the Java Console window and bring it forward (give it focus), the pData exception does not occur.  A Google search for "NullPointerException: null pData" reveals numerous other reports of the "null pData" exception occurring for applets.

Print preview on second display screen jumps back to main screen on zoom/unzoom
Java did not provide an API for properly handing multiple monitors until the addition of the class java.awt.GraphicsEnvironment and the method getScreenDevices() and related APIs.  In order to keep J2PrinterWorks compatible across all Java JDKs, the J2PrinterWorks internal PrintPreviewDialog class does not support calling these APIs to determine the state of a multiple monitor configuration so as to remain on a secondary screen during certain operations such as zoom.  However, with the publishing of the source code for the internal PrintPreviewDialog class as part of J2PrinterWorks 5.0, developers who which to support this capability on JDKs where it is enabled are now able to do so.

Memory leak when calling print preview dialog repeatedly - Bug Parade 6497929
Fixed in JDK 1.7, workarounds in Bug Parade report
This problem is due to a bug in the Java Dialog class because of Java maintaining a list of modal dialogs and not properly releasing them when Dialogs are completed.  In previous releases of J2PrinterWorks, the internal print preview dialog held a reference to your printing Pageable, which could potentially hold references to large amounts of user data such as TableModels, StyledDocuments, images, etc, thereby preventing garbage collection from freeing up this memory after repeated calls to the print preview dialog.  In J2PrinterWorks 5.0, the problem of holding a reference to your Pageable was fixed, but the Java bug still causes the Dialog class itself to leak.  The Dialog leak problem has been fixed in JDK 1.7 and the above Bug Parade report contains a number of user-supplied code workarounds for earlier JDKs.

ArrayIndexOutOfBoundsException from Win32PrintService under JDK 1.4.2_09 and JDK 1.4.2_10
Regression from JDK 1.4.2_08, fixed again in 1.5.0
Workaround in J2PrinterWorks 4.1
This bug occurs on Windows and appears to be specific to these particular JDK releases.  It occurs when invoking the page setup or print dialog the first time using the cross-platform dialogs.  Workarounds include reverting to JDK 1.4.2_08 or moving to JDK 1.5.0.  Another workaround is to use the native print dialogs, i.e., call setCrossPlatformDialogs(false).  Since the exception appears to occur only the first time, another workaround is to call: 

    try {
         printer.setSeparatePrintThread(false); // else exception from background thread

         printer.print(); // JDK 1.4.2_09 bug, throws exception first time

    } catch (Exception e) { printer.print(); }

J2PrinterWorks 4.1 contains a workaround that avoid this problem altogether and works under all JDKs.

Doesn't handle default landscape printer page orientation
Fixed in JDK 1.4 + J2PrinterWorks 3.3
If you have the default (i.e., set in your OS) page orientation of your printer set to landscape, then prior to J2PrinterWorks 3.3, this default landscape printer page orientation was ignored and printing behaved as though the default orientation was portrait.  This has now been fixed.  However, a default landscape orientation cannot be made to work properly under JDK 1.3.0 and 1.3.1 because of a problem with how JDK 1.3.x reports default pages and validates PageFormat instances, resulting in either incorrect margins or margin calculation errors during printing.  There does not appear to be a workaround for this problem, so if you are using JDK 1.3.0 and JDK 1.3.1 your printers must have a default page orientation of portrait.

Native print and page setup dialogs are non-modal - Bug Parade 4273333, Bug Parade 4785920
Fixed in JDK 1.4 and again in JDK 1.4.2
On Windows, the Java native print and page setup dialogs come up non-modal, so you can bring your application window back to the front and click on other buttons and menu items, including reinvoking the print and page setup dialogs.  This is a bug in Java which Sun has fixed, broken, and fixed again.  It was a bug in JDK 1.2.2 through 1.3.1.  It was fixed in 1.3.1_03 and works OK in JDK 1.4.  But then Sun broke it again in JDK 1.4.1.  They fixed it again in 1.4.1_05 and it remains fixed in JDK 1.4.2.   The cross-platform print and page setup dialogs don't have the problem and are modal across all 1.4.x JDKs. 

Cross-platform print dialog always says Pages 1 to 1 - Bug Parade 4886087
When printing using the JDK 1.4.x cross-platform print dialog, the page range always displays as Pages 1 to 1 rather than the upper bound being the number of pages of the Pageable.  The behavior in the native print dialog is correct.  A workaround is to use the PageRanges print request attribute to force the desired values (but then the page range option becomes the default instead of "All").

After using setPrinter(), native print dialogs ignore setNumberOfCopies > 1 (JDK 1.4 and 1.4.1) - Bug Parade 4694495
Fixed in JDK 1.4.2.
When using the native print dialogs and programmatically setting the printer using setPrinter(), the number of copies shown in the print dialog always is 1 rather than the value most recently sent by setNumberOfCopies.  Workaround: use cross-platform dialogs.
 

Print to file dialog window opens in back
When printing on Windows platforms, the Windows print dialog includes a checkbox for the option "Print to file".  If that option is checked and the print dialog "OK" button pressed, the next step is to display a standard Windows file dialog for purposes of specifying the file to which to print. Unfortunately, this file dialog opens in back of the other open Java windows, requiring the user to explicitly bring this dialog to the front using the Windows taskbar or to move or minimize the other windows to uncover it.  We have not identified a way to prevent this.  A workaround is to temporarily minimize the other open Java windows just before the J2Printer print method is called.  You can also use the J2PrinterWorks "print-to-file" feature. 

Some printers report margins reversed under LANDSCAPE (JDK 1.4 and 1.4.1) - Bug Parade 4694478
Some printers (e.g. an HP OfficeJet G85) show Page Setup dialog margins values that are reversed (top/bottom and left/right) from the actual behavior.  It is as though the margins are treated as REVERSE_LANDSCAPE rather than LANDSCAPE.  This problem was not present prior to JDK 1.4 and has been reported to Sun.  Workaround: use topMargin=bottomMargin and leftMargin=rightMargin.

Background windows don't refresh when dragging Page Setup dialog
Fixed in JDK 1.5.0
This is a known bug in Java, see Java Bug Parade reports 4507585 , 4394889 , and 4616183 .  These reports indicate that the same problem should occur with the print dialog, but in J2PrinterWorks only the page setup dialog has the problem.  This is thanks to our setSeparatePrintThread() feature, which by default is true, allowing the GUI thread to refresh your windows when you print (or print preview).  But we didn't use a separate thread when calling the page setup dialog.

There are several workarounds:

1) Call showPageSetupDialog() from a separate thread, e.g.:

  new Thread() { public void run() { j2printer.showPageSetupDialog(); } }.start();
 
2) Create your own page setup dialog, which you can base on any one of our Page Setup Dialogs samples (see "Sample Programs").  These are true JDialogs and don't have the problem.

3) Use the new JDK 1.4 cross-platform print and page setup dialogs which don't have the problem.

Main window stays in background after page setup or print dialog - Bug Parade 4514422
Fixed in JDK 1.4.1.
This problem showed up in JDK 1.3.1_04 and was still present in JDK 1.4.  You can fix this using appropriately placed "toFront() " calls on your main window in conjunction with a PrintingStatusListener (see J2Printer "AdditionalCapabilities" ).  Several of the J2PrinterWorks sample applications (in particular J2PrinterWorksTestApplication, J2TextPrinterTestApplication, J2TablePrinterTestApplication, and J2TreePrinterTestApplication) show how to implement this workaround.

Right and bottom margins values drift (up or down) over repeated Page Setup dialog calls (JDK 1.4) - Bug Parade 4694507
Fixed in JDK 1.4.1.
If you call the page setup dialog repeatedly, the margins values slowly increase or decrease, in what looks like rounding errors when converting to/from inches to 72dpi "points".  Workaround: reset your desired margins each time before calling page setup dialog.

Print Dialog doesn't show default printer (JDK 1.2.x)
Fixed in JDK 1.4.1.
Under JDK 1.2, your default printer is not automatically chosen when the Print Dialog comes up, and you will need to select it manually. 

Number of copies is ignored (JDK 1.2.x)
Fixed in JDK 1.3.
The J2TextPrinter setNumberOfCopies(int) method is ignored under JDK 1.2.2 and 1.3beta releases.  J2TextPrinter is designed to copy your current numberOfCopies setting into the Print Dialog, but the Print Dialog number of copies field always comes up as 1.  The user can change the number of copies in the Print Dialog, which will cause that specified number of copies to print, but this value is not provided back to J2TextPrinter, so your numberOfCopies property will be unchanged.  Your numberOfCopies setting is also ignored if you print without a Print Dialog.  This bug is fixed in JDK 1.3 final (see Bug Parade 4168555). 

Some Print Dialog options can't be set or read (JDK 1.2.x and JDK 1.3.x)
Fixed in JDK 1.4.
Various of the options in the Print Dialog work properly using J2TextPrinter including:
    a) Page range: all vs a range of pages
    b) Collate
    c) Print to file
However, prior to JDK 1.4, none of the above settings are reported back to J2TextPrinter nor was there a Java API that allowed them to be set programmatically (see Bug Parade 4252109).

In addition, hitting "Properties" (along side the printer choice), brings up a printer driver-specific dialog that generally includes these options:
    a) Last page prints first
    b) Portrait vs. landscape
Depending upon the printer driver, others settings may be made at the driver level, i.e., out from under Java.  The first of these works correctly on the printers we have tested.  The second of these doesn't work right, as it does not allow J2TextPrinter's pagination, page width, margins, and other layout recalculations to be invoked.  Use instead the J2TextPrinter orientation property.  The J2TextPrinter orientation property is displayed and can be changed in the standard Page Setup dialog and is known to Java and therefore J2TextPrinter, allowing it to reformat the orientation correctly.  

Print job name is ignored (JDK 1.2.x)
Fixed in JDK 1.3.
The J2TextPrinter setPrintJobName(String) method is ignored under JDK 1.2.2 and 1.3beta releases (see Bug Parade 4205601).  A default print job name is always used. 

Page Setup dialog comes up slow (JDK 1.2.x)
Fixed in JDK 1.3.
Under JDK 1.2, the Java Page Setup dialog (which brings up a standard OS page setup dialog) takes about 20 seconds to come up on Windows 95 and 98.  A bug report has been filed with Sun about this problem.  J2TextPrinter does display a watch cursor while the Page Setup dialog is coming up.    Under JDK 1.2, you might prefer to implement your own Page Setup dialog, which you will want to do anyway if there are other J2TextPrinter settings you would like your users to be able to specify.  The detailed J2TextPrinterPageSetupDialog provided as part of J2TextPrinterTestApplication comes up fast.  

Page Setup margins always initialize to 1" (JDK 1.2.x)
Fixed in JDK 1.3.
J2TextPrinter is designed to copy your current margin settings and portrait/landscape choice into the standard Page Setup dialog.  Unfortunately, a bug in JDK 1.2.2 and JDK 1.3 beta (see Bug Parade 4197377) causes the Page Setup dialog to ignore the margin values provided and to always display instead 1" margins on all four sides.  If you change these and click "OK", these new settings will be successfully copied back into your margin settings and used during printing.

The minimum Page Setup margins you can enter are dependent on the current default printer choice.  On Windows, these minimum values give the unprintable margins for the current default printer, so you can try setting them all to 0 to see what the print driver regards as its minimum margins and use these for the "unprintable margin" values (see next).

Unlike the case for margins, the J2TextPrinter portrait/landscape property does display correctly in the JDK 1.2 Page Setup dialog.  Any change the user makes is copied back into the corresponding J2TextPrinter property, and printing does honor this setting.  

Unprintable margins can't be automatically detected (JDK 1.2.x)
Fixed in JDK 1.3.
Virtually all printers have some space around the four edges of the page that are unprintable. Some operating systems (e.g. Macintosh) use a printing coordinate system that corresponds to the printable area.  Other operating systems (e.g. Unix) cannot detect the printable area and use instead a printing coordinate system that corresponds to the entire physical page (and therefore will not print at some coordinate positions).  In addition, Sun has changed their Windows implementation from printable area coordinates (Mac-like) under JDK 1.2 to physical page coordinates (Unix-like) under JDK 1.3.  Like most end-user applications, J2TextPrinter defines its left, right, top, and bottom margins relative to the physical page, so that specifying a 1" margin results in a real 1" margin on the physical page.  For this to work, J2TextPrinter needs to know the size of the unprintable left, right, top, and bottom margins for the current printer and whether your OS is one of those that defines its coordinate system as the printable area.

J2TextPrinter provides properties you can use to control these values yourself.  In addition, Java 2 has a method validatePage that is supposed to allow J2TextPrinter to determine the unprintable margins automatically.  This works correctly under JDK 1.3 final, but it is unimplemented in JDK 1.2.2 and JDK 1.3 beta (see Bug Parade 4252108), so on these releases a set of values typical of HP laserjet printers is used.   In addition J2TextPrinter automatically detects your OS and Java release version and sets the value of the J2TextPrinter property printableAreaCoordinates to be true for Macintosh and Windows under JDK 1.2 and false for Unix and Windows under JDK 1.3.  For any other OS, you will need to set this value yourself (the default is false, i.e., Unix-like).

On Windows, you can use the Page Setup dialog to determine the unprintable margins for any given printer.  If you set the margins to 0, the Page Setup dialog will reset them to the actual unprintable margin values you want.  If you want to do this for some printer other than the default printer, first change the printer using the Page Setup "Printer" button (this choice is not remembered or displayed with the regular Print Dialog comes up).

On top of all this, some printers report minimum margins that are too close to the cut-off and not really enough in practice.  Setting your margins to a fraction of an inch more than these "unprintable" margins is often a good idea.  

Reverse Landscape unimplemented (JDK 1.2.x)
Fixed in JDK 1.3.
J2TextPrinter supports portrait and landscape printing orientations, but reverse landscape was not implemented in Java (see Bug Parade 4236095) under JDK 1.2 and  JDK 1.3beta.  Note that REVERSE_LANDSCAPE is simply a 180 degree rotation on the page relative to LANDSCAPE.  It is not a left-to-right reversal of the LANDSCAPE image, such as the option provided by some systems (notably Macintosh) to facilitate printing on the back side of transparencies to overcome printer paperpath "curl".  

Intermittent JVM.DLL crash under on Windows 98 (JDK 1.2.x)
Fixed in JDK 1.3.
Sun reports in Bug Parade 4293262 that printing under JDK 1.2.2 on Windows 98 can intermittently cause an IOH exception in the Java JVM.DLL.  This problem has not been observed under Windows 95 or NT.  It appears to happen for some printers and not others.  Switching printers, rebooting, printing with other applications, or changing the content being printed often (but not always) clears it up. 


© Copyright 2009, Wildcrest Associates (http://www.wildcrest.com)