Note that there are some explanatory texts on larger screens.

plurals
  1. POPrinting a JFrame and its components
    primarykey
    data
    text
    <p>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:</p> <p><a href="http://docs.oracle.com/javase/tutorial/2d/printing/gui.html" rel="nofollow">http://docs.oracle.com/javase/tutorial/2d/printing/gui.html</a></p> <p>it was very helpful, I tried to use that code in my program by placing this inside the actionperformed method of my print button:</p> <pre><code>PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) { try { job.print(); } catch (PrinterException ex) { /* The job did not successfully complete */ } } </code></pre> <p>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. </p> <p>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? </p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload