|
Description
|
The method "getCopies()" does not return the number of copies
in case the user changed it in the printDialog(). When you
do a setCopies() the number of copies will be shown in the
printDialog(), but when you change it and call getCopies() you
will always get the number back you sent in using "setCopies()".
Example:
import java.awt.*;
import java.awt.print.*;
import java.awt.print.PageFormat;
import java.awt.geom.*;
import java.lang.*;
public class PrintTest {
public static void main(String[] args) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setCopies(1); // this works fine, 2 is displayed in the printer dialog
PageFormat pfDefault;
if (job.printDialog()) {
pfDefault=job.pageDialog(job.defaultPage());
int cnCopies=job.getCopies(); // this will always return 2 although changed in the dialog
Book bk = new Book();
bk.append(new CClippedRect(),pfDefault);
job.setPageable(bk);
try {
job.print();
}
catch (Exception exc) {
System.out.println("Printer Exception");
}
}
}
}
class CClippedRect implements Printable {
public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException {
Graphics2D g2=(Graphics2D)g;
BasicStroke stroke=new BasicStroke(0.2f);
g2.setStroke(stroke);
g2.setColor(Color.black);
Rectangle r=new Rectangle();
g2.getClipBounds(r);
//g2.drawRect(r.x+5,r.y+5,r.width-10,r.height-10); // bottom line will not be printed at all
r.x+=10;
r.y+=10;
r.width-=20;
r.height-=20;
g2.drawLine(r.x,r.y,r.x+r.width,r.y);
g2.drawLine(r.x,r.y,r.x,r.height);
g2.drawLine(r.x+r.width,r.y,r.x+r.width,r.height);
g2.drawLine(r.x+r.width,r.height,r.x,r.height);
// Remove next comment in oder to see bug
// g2.drawRect(r.x,r.y,r.width,r.height-5); // bottom line will be printed much too fat
return(PAGE_EXISTS);
}
}
(Review ID: 48107)
======================================================================
|