0

I'm trying to print out a jpanel and it's components to a 4X2 label, I'm new to java and I'm not sure were to go next on how to adjust the Paper's imageable height. The following is my code block for printing. I appreciate any help or direction you can point me to.

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         

PrinterJob pj = PrinterJob.getPrinterJob();
  pj.setJobName(" Print Component ");

  pj.setPrintable (new Printable() {    
    public int print(Graphics pg, PageFormat pf, int pageNum){
      if (pageNum > 0){
      return Printable.NO_SUCH_PAGE;
      }



      return Printable.PAGE_EXISTS;
    }
  });
  if (pj.printDialog() == false)
  return;

  try {
        pj.print();
  } catch (PrinterException ex) {
        // handle exception
      System.out.println(ex);
  }


    }

1 Answers1

0

See validatePage

public abstract PageFormat validatePage(PageFormat page)

Returns the clone of page with its settings adjusted to be compatible with the current printer of this PrinterJob. For example, the returned PageFormat could have its imageable area adjusted to fit within the physical area of the paper that is used by the current printer.

Parameters: page - the PageFormat that is cloned and whose settings are changed to be compatible with the current printer

Returns: a PageFormat that is cloned from page and whose settings are changed to conform with this PrinterJob.

See also

Community
  • 1
  • 1