Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing arguments to implemented method java
    text
    copied!<p>I have a class that implements Printable. I'm trying to somehow get values from text fields into the print method but can't seem to work out how to do it. </p> <pre><code>public class TreePrint extends javax.swing.JFrame implements Printable{ </code></pre> <p>Then this is the action for when user has selected the items to print: </p> <pre><code>private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) { goPrint(); } public void goPrint() { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(new TreePrint()); // boolean doPrint = job.printDialog(); job.print(); } @Override public int print(Graphics g, PageFormat pf, int page) throws PrinterException { Koks koksSelected = (Koks) combobox_skirne.getSelectedItem(); System.out.println(combobox_skirne.getSelectedItem()); if (page &gt; 0) { return NO_SUCH_PAGE; } System.out.println(koksSelected.getSkirne()); return PAGE_EXISTS; } </code></pre> <p>The problem is that I can't get the selected item or text value in the print method. I can get them in the go print or btnPrintActionPerformed, but in the print() it always shows the selected value that was there when the program was first run. I can post more code if needed, but it is quite long. Im sure this is a basic problem with implemented methods but I couldn't find an answer to it.</p> <p>This is a similar (the same?) question: <a href="https://stackoverflow.com/questions/8324388/passing-parameters-to-the-print-method-java">Passing Parameters to the print method (JAVA)</a></p>
 

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