title: having issue with printing text, image or report on printer in java 11
body: <p>I have issue with printing any icon, text or report in java 9 or latest versions. My coding work perfectly on java 8 but we java 9 till java 11 it is working. It cannot print the document.</p>
  
  <pre><code>private void cmdPrintActionPerformed(java.awt.event.ActionEvent evt) {                                         
      try {
  
          printComponent(frmDoc, true);
          printComponent(frmDoc, false);
      } catch (PrinterException exp) {
          javax.swing.JOptionPane.showMessageDialog(this, exp.getMessage());
      }
  }
  
  
  
  public class ComponentPrinter implements Printable{
  private Component comp;
  private boolean fill;
  public ComponentPrinter(Component comp, boolean fill) {
      this.comp = comp;
      this.fill = fill;
  }
  @Override
  public int print(Graphics g, PageFormat format, int page_index) throws PrinterException {
      if (page_index &gt; 0) {
          return Printable.NO_SUCH_PAGE;
      }
  
      Graphics2D g2 = (Graphics2D) g;
      g2.translate(format.getImageableX(), format.getImageableY());
      double width = (int) Math.floor(format.getImageableWidth());
      double height = (int) Math.floor(format.getImageableHeight());
      if (!fill) {
          width = Math.min(width, comp.getPreferredSize().width);
          height = Math.min(height, comp.getPreferredSize().height);
  
      }
  
      comp.setBounds(0, 0, (int) Math.floor(width), (int) Math.floor(height));
      if (comp.getParent() == null) {
          comp.addNotify();
      }
      comp.validate();
      comp.doLayout();
      comp.printAll(g2);
      if (comp.getParent() != null) {
          comp.removeNotify();
      }
      return Printable.PAGE_EXISTS;
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public static void printComponent(JComponent comp, boolean fill) throws PrinterException {
      PrinterJob pjob = PrinterJob.getPrinterJob();
      PageFormat pf = pjob.defaultPage();
      pf.setOrientation(PageFormat.PORTRAIT);
  
      PageFormat postformat = pjob.pageDialog(pf);
      if (pf != postformat) {
          //Set print component
          pjob.setPrintable(new ComponentPrinter(comp, fill), postformat);
          //pjob.print();
  
          //pjob.
          if (pjob.printDialog()) {
              pjob.print();
          }
      }
  }
  </code></pre>
  
  <p>When I run the program I got this error in console.
  <img src="https://i.stack.imgur.com/DrYp0.png" alt="output error"></p>