FULL PRODUCT VERSION :
Java 1.4.2_04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM
(mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows XP
EXTRA RELEVANT SYSTEM CONFIGURATION :
HP LaserJet 1300
A DESCRIPTION OF THE PROBLEM :
When HP LaserJet 1300 is set to be my default printer, I get the following exception when I first bring up the print dialog (using 1.4 printing API):
java.lang.ArrayIndexOutOfBoundsException: -1
at sun.print.Win32PrintService.getMediaTrays(Unknown Source)
at sun.print.Win32PrintService.getSupportedAttributeValues(Unknown Source)
at sun.print.ServiceDialog$MediaPanel.updateInfo(Unknown Source)
at sun.print.ServiceDialog$PageSetupPanel.updateInfo(Unknown Source)
at sun.print.ServiceDialog.updatePanels(Unknown Source)
at sun.print.ServiceDialog.<init>(Unknown Source)
at javax.print.ServiceUI.printDialog(Unknown Source) ...
Subsequent attempts to print within the same application session succeed.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Set HP LaserJet 1300 to be your system's default printer
Run a test application that brings up the 1.4 print dialog.
Exception is thrown.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect print dialog to open, allowing printing of application.
ACTUAL -
Exception is thrown.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ArrayIndexOutOfBoundsException: -1
at sun.print.Win32PrintService.getMediaTrays(Unknown Source)
at sun.print.Win32PrintService.getSupportedAttributeValues(Unknown Source)
at sun.print.ServiceDialog$MediaPanel.updateInfo(Unknown Source)
at sun.print.ServiceDialog$PageSetupPanel.updateInfo(Unknown Source)
at sun.print.ServiceDialog.updatePanels(Unknown Source)
at sun.print.ServiceDialog.<init>(Unknown Source)
at javax.print.ServiceUI.printDialog(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.ServiceUI;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import java.awt.*;
import java.awt.print.Printable;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
public class PrintTest{
private JFrame fFrame;
private MyTextArea fTextArea;
public PrintTest(){
//bring up a 1.4 print dialog for a text area.
fFrame = new JFrame("Text Area");
fTextArea = new MyTextArea("foo bar test\n" +
"foo bar test\n" +
"test test test");
fFrame.getContentPane().add(fTextArea);
fFrame.setSize(200, 200);
fFrame.setVisible(true);
print();
}
public void print(){
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintService defaultService =
PrintServiceLookup.lookupDefaultPrintService();
final PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
PrintService[] printService = // using pras above causes
problems-- no printers returned
PrintServiceLookup.lookupPrintServices(flavor, new HashPrintRequestAttributeSet());
Point location = fFrame.getLocationOnScreen();
ServiceUI.printDialog(null, location.x + 100, location.y + 100,
printService, defaultService, flavor, pras);
}
public class MyTextArea extends JTextArea implements Printable{
public MyTextArea(String text){
super(text);
}
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException{
return -1;
}
}
public static void main(String[] args){
new PrintTest();
}
}
---------- END SOURCE ----------
###@###.### 10/5/04 22:28 GMT