B
Bernard Segonnes
Hi,
I will have several pages to print.
I need to have an overview of 1 page at the time (in a JPanel), and
the possibility to use the same JPanel to display another page.
This JPanel will be able to print all pages.
1)Is it possible to use the same method (drawPage() ) to print 1 page
(called from print() and from paint() ) ?
2) How can I know the page number I have to display in paint() ?
3) How do I know how to create a new page ?
4) How can I count the number of pages before printing (in the oveview
on the screen) ?
book = new Book();
printAndOverview = new PrintAndOverview();
book.append(printAndOverview,myPageFormat);
job.setPageable(book);
....
private class PrintAndOverview extends JPanel implements Printable {
public PrintAndOverview() {
super();
setVisible(true);
}
public int print(Graphics g, PageFormat format, int pageIndex) {
super.print( g);
drawPage((Graphics2D) g);
return Printable.PAGE_EXISTS;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
drawPage((Graphics2D) g);
}
private void drawPage(Graphics2D g2){
g2.drawString("page number XXX",10,10);
..... a lot of stuff
}// drawPage()
}
Thanks for your help
I will have several pages to print.
I need to have an overview of 1 page at the time (in a JPanel), and
the possibility to use the same JPanel to display another page.
This JPanel will be able to print all pages.
1)Is it possible to use the same method (drawPage() ) to print 1 page
(called from print() and from paint() ) ?
2) How can I know the page number I have to display in paint() ?
3) How do I know how to create a new page ?
4) How can I count the number of pages before printing (in the oveview
on the screen) ?
book = new Book();
printAndOverview = new PrintAndOverview();
book.append(printAndOverview,myPageFormat);
job.setPageable(book);
....
private class PrintAndOverview extends JPanel implements Printable {
public PrintAndOverview() {
super();
setVisible(true);
}
public int print(Graphics g, PageFormat format, int pageIndex) {
super.print( g);
drawPage((Graphics2D) g);
return Printable.PAGE_EXISTS;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
drawPage((Graphics2D) g);
}
private void drawPage(Graphics2D g2){
g2.drawString("page number XXX",10,10);
..... a lot of stuff
}// drawPage()
}
Thanks for your help