• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing Solved but?

 
Charlie Boss
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,
I solved my printing multiple pages issue but now I have another problem. To be able to print, i create an instance of my Display class, below, and append it to my book (casting it to Printable first).
Now since the end user might be printin lots of pages i do not want to make my JFrame visible. I want it to be printed in the background. However if i do a setVisible(false) on my JFrame, my pages still print but they come out BLANK. I figure its because i'm doing a "paint" in my print routine. How can i print my pages in the background without making my frames visible. Thankx.
public class Display
extends JFrame implements java.awt.print.Printable{
JPanel c = new JPanel();
public void makeComponents(JPanel c){//makes display components
}
Display(String title){
super(title);
makeComponents(c);
this.getContentPane().add(c);
this.setSize(672,792);
this.setVisible(true);
//i want => this.setVisible(false);
}
public int print(Graphics g, java.awt.print.PageFormat pf, int pi) throws java.awt.print.PrinterException {
Graphics2D g2 = (Graphics2D) g;
g2.translate(pf.getImageableX(), pf.getImageableY());
paint (g2);
return java.awt.print.Printable.PAGE_EXISTS;
}
}
[This message has been edited by Charlie Boss (edited June 19, 2001).]
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Charlie,
Until java includes headless graphics into toolKit you must make any component visible to be able to print it out.
I just set the frame location to 3000,3000 so that it doesn't show on the display (except for the task bar).
Good Luck,
Manfred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic