• Post Reply Bookmark Topic Watch Topic
  • New Topic

JInternalFrame

 
rama krishnan
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to print the JInternalFrame page?

first I used below method, I cann't to print, because its only accepting the Frame & printing Frame page only

"java.awt.Toolkit.getDefaultToolkit().getPrintJob()"

second time I tried below code

PrinterJob.getPrinterJob();
printJob.setPrintable(this);
printJob.print();

that time also i didn't get the print out.

Give me the solution for this.
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "this"? It's a Printable, but of what class? If you have developed it, can you please show us the code?

Also, I found out from experience that sometimes you don't want to use a JFrame or JInternalFrame but its RootPane instead.
 
rama krishnan
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob, thanks for replying,
I'm using this code only to print the JInternalFrame screen
but i get only empty page as printout

PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception ex) {
ex.printStackTrace();
}
}

public int print(Graphics g, PageFormat pf, int page) throws PrinterException {

if (page > 0) {
return NO_SUCH_PAGE;
}


Graphics2D g2d = (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY());

//g.drawString("Hello World", 100, 100);

return PAGE_EXISTS;
}

[ November 26, 2008: Message edited by: muthurama krishnan ]
[ November 26, 2008: Message edited by: muthurama krishnan ]
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That can't be your code because it will print absolutely nothing. You have to use the Graphics object to do some printing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!