• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JInternalFrame

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic