Java Printing: printing wrong page range when All selected

Greetings everyone!

I'm working with JPS (Java Printing API http://java.sun.com/j2se/1.4.2/docs/guide/jps/index.html) and have following issue.

In our application we re-use printerJob object in order to preserve user settings (printer, paper format etc.) by storing it in application scope.

However following scenario provides to incorrect printing behaviour:

1. User selectes in print dialog to print pages range from 2 to 3

2. Pages 2 and 3 are printed

3. User calls Print dialog once more and this time he/she selects All pages to print

4. Only Pages 2 and 3 are printed! However all pages are expected to be printed.

I've tested this issue with JDK 1.5.0_06 and JDK1.6.0.

This issue doesn't appear with JDK 1.4.2_x.

Below is a code of printing functionality (please note that printJob variable is stored in application scope and initialized only once):

import java.awt.Graphics;

import java.awt.print.Printable;

import java.awt.print.PageFormat;

import java.awt.print.PrinterException;

import java.awt.print.PrinterJob;

publicclass T{

static PrinterJob printJob;

publicstaticvoid print(){

// Set working printable to print pages

printJob.setPrintable(new Printable(){

publicint print(Graphics graphics, PageFormat pageFormat,

int pageIndex)throws PrinterException{

pageIndex++;

if (pageIndex < 10){

System.out.println("Printing page: " + pageIndex);

graphics.drawString("Page #" + pageIndex +" of 9",

(int) pageFormat.getImageableX() + 5,

(int) pageFormat.getImageableY() + 20);

graphics.dispose();

return PAGE_EXISTS;

}else{

return NO_SUCH_PAGE;

}

}

});

// Display Print dialog

if (!printJob.printDialog()){

System.out.println("\tPrinting canceled by user");

return;

}

try{

printJob.print();

}catch (PrinterException e){

}

}

publicstaticvoid main(String[] args){

printJob = PrinterJob.getPrinterJob();

System.out.println(" -=- Starting printing #1 -=-");

print();

System.out.println(" -=- Starting printing #2 -=-");

print();

}

}

Can anyone help me?

Thank you,

Vlad

[4036 byte] By [VladMa] at [2007-11-26 19:43:20]
# 1
Any thougths on this?
VladMa at 2007-7-9 22:26:22 > top of Java-index,Desktop,Core GUI APIs...