Friday, 15 August 2014

java - Trigger Jasper Report Viewer Print Button programmatically -


I have the following item class where I have already applied "JPViewer" to "Escape" except for the press, now I need to trigger "Space" on the keypress. JRVire's print button Please guide me if anyone has any idea (code should be "Go to the" section)

 < Code> Public category IReport javax.swing.JFrame {public IReport (string Filename, hashmap parameter) {super ("report viewer"); // addWindowListener (this); SetIcon (); Try {DefaultJasperReportsContext Reference = 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 ()); JR Weaver Viewer = new JRWiver (print); Container c = getContentPane (); C.add (viewer); // When the User Press Association reports the viewer stops --------------------- the viewer. Past inputmap (jcomantant. WHEN_IN_FOCUSED_WINDOW) Input (keystraktagetocstroke (KEV.VK_KSKE, 0), "Skip"); Viewer.getActionMap (). Put ("left", new abstract action () {@ Override Public Zero Action Perfid (Action Event E) {Settlement ();}}); // ------------------------------------------------ --------------------- // When the user press space should be triggered print button ----------------- - --- Viewer Gate Input Measure (Jakomant. WHEN_IN_FOCUSED_WINDOW) Input (keystroke. Gatek (KEV.VK_SPACE, 0), "print"); Viewer.getActionMap (). Put ("Print", New Abstract Action () {@ Override Public Records ActionPerfed (Action code e) {// Code should go here}}); // ------------------------------------------------ ---------------------} hold (Exception pre) {ex.printStackTrace (); } This.setExtendedState (MAXIMIZED_BOTH); This.setDefaultCloseOperation (DISPOSE_ON_CLOSE); }}  

As far as I know, the only way is that you do this Can expand code JRViewer .

When the print button is clicked, the method clicked on btnPrintActionPerformed is Visibility, it means that only classes in the same package that method Can use.

The print button, however, is protected visibility, therefore, it is accessible in sections within the same package as well as subclasses.

So, you can create a square that increases the JRViewer and the print button.

  Public class expands MyCustomJRViewer JRViewer {public JButton getPrintButton () {return btnPrint; }}  

Use your custom code JRViewer, and do your action in the following:

  myCustomViewer.getActionMap (). Put ("print", new abstract action () {@ Override Public Voice Action Crore (Action Event E) {myCustomViewer.getPrintButton (). Actioned (e);}});  

No comments:

Post a Comment