Organizational Research By

Surprising Reserch Topic

printing a jframe and its components

printing a jframe and its components  using -'java,swing,graphics,printing,jframe'

I have been working in a big program and one of its functionalities should be to print the contents of the main window. I checked the API and found this example:

it was very helpful, I tried to use that code in my program by placing this inside the actionperformed method of my print button:

PrinterJob job = PrinterJob.getPrinterJob();
     boolean ok = job.printDialog();
     if (ok) {
         try {

         } catch (PrinterException ex) {
          /* The job did not successfully complete */

If I click the print button, I get a printer dialog and when I tell it to print, it just prints a blank document. I know the above code is not all I need, as I've seen in the API's examples there is a print() method, but apparently they never call it, so  it is pretty confusing. I've tried calling and using it many times, but with no success.

Also, I think that when I finally get it to print, my window will need to be printed in the landscape orientation, it even may need some scaling. Any ideas on how to do that?  

I would like any useful help to help me implement this code successfully. I know I should be able to do it by myself just by checking the documentation (I've tried for almost 2 days now) but I can't get it to work. I've learned all the programming I know through the internet. Any help will be greatly appreciated.

asked Sep 22, 2015 by ajit.chavhan
0 votes

Related Hot Questions

2 Answers

0 votes
answered Sep 22, 2015 by nimisha.jagtap
0 votes
answered Sep 22, 2015 by android_master