title: Trigger Jasper Report Viewer Print Button programmatically
body: <p>I have the following IReport class where I have already implemented quit JRViewer on "Escape" Keypress as follows, Now I need to trigger Print button of the JRViewer on keypress of "Space". Please guide me on this if anyone have an idea. (The code should come in the "CODE SHOULD GO HERE" section)</p>
  
  <pre><code>public class IReport extends javax.swing.JFrame {
  
      public IReport(String filename, HashMap parameter) {
  
          super("Report Viewer");
  
          //addWindowListener(this);
          setIcon();
  
          try {
              DefaultJasperReportsContext context = DefaultJasperReportsContext.getInstance();
              JRPropertiesUtil.getInstance(context).setProperty("net.sf.jasperreports.xpath.executer.factory",
                      "net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory");
              JasperPrint print = JasperFillManager.fillReport(filename, parameter, DatabaseService.getConnection());
  
              JRViewer viewer = new JRViewer(print);
  
              Container c = getContentPane();
  
              c.add(viewer);
  
              //When user press Escape report viewer get closed---------------------
              viewer.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "quit");
              viewer.getActionMap().put("quit", new AbstractAction() {
  
                  @Override
                  public void actionPerformed(ActionEvent e) {
                      dispose();
  
                  }
  
              });
              //---------------------------------------------------------------------
  
              //When user press space print button should be triggered---------------------
              viewer.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "print");
              viewer.getActionMap().put("print", new AbstractAction() {
  
                  @Override
                  public void actionPerformed(ActionEvent e) {
  
                      //CODE SHOULD GO HERE
  
                  }
  
              });
              //---------------------------------------------------------------------
  
          } catch (Exception ex) {
              ex.printStackTrace();
          }
  
          this.setExtendedState(MAXIMIZED_BOTH);
          this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  
      }
  
  
  }
  </code></pre>