• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

JInternalFrame

 
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.
 
Sheriff
Posts: 21922
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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: 21922
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic