Hello everyone I am trying to print out a load of printables on different pages, I have made the containing class Pageable, and implemented all the methods as below, the acutal printing is done in printAllGraphs() :
PrinterJob printerJob;
PageFormat pageFormat;
int numberOfPages;
public void printAllGraphs(){
//this.chart.print();
numberOfPages=this.dataList.size();
System.out.println("Number of pages : " + numberOfPages);
printerJob = PrinterJob.getPrinterJob();
printerJob.setJobName(" Print Component ");
printerJob.setPageable(this);
setPageFormat();
if (printerJob.printDialog() == false)
return;
try {
printerJob.print();
} catch (PrinterException ex) {
System.err.println(ex.getMessage());
}
}
public int getNumberOfPages() {
return numberOfPages;
}
public void setPageFormat()
{
pageFormat = printerJob.pageDialog(printerJob.defaultPage());
}
public PageFormat getPageFormat(int pageNumber)
throws IndexOutOfBoundsException {
return pageFormat;
}
public Printable getPrintable(int pageNumber) throws IndexOutOfBoundsException {
System.out.println("Getting printable for page : "+pageNumber);
System.out.println("Returning " + chart.chartPanel);
return chart.chartPanel;
}
My problem is that its only printing the first page, which it does fine. Here is an example of the output:
Number of pages : 3
Getting printable for page : 0
Returning saiman.uiobjnew.DynamicChartPanel[...]
Getting printable for page : 1
Returning saiman.uiobjnew.DynamicChartPanel[...]
as you can see, its getting the printable for page 0 and 1 fine, but there are three pages and it never tries to get one for the last page, so i can assume its failed somehow before printing the second page and just given up (resulting in my one page document)
I was wondering if anyone with any experience printing could take a look, see if i am doing anything wrong.
Thanks