Results 1 to 16 of 16
Thread: GUI printing
- 05-17-2010, 06:32 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
GUI printing
Hi , i created small gui frame and wanted to take a print out of that frame with all the contents. it was running successfully without any errors in my machine (xp service pack 3), but when i tried to run it another machine (xp service pack 2) with jre environment i couldn't take a hard copy , sheet is processing without any marks (blank paper). Can any one explain why this is happening..
Thanks,
Uthpala
- 05-17-2010, 06:44 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
How did you run your application in the second machine, with the source or did you build the application?
- 05-17-2010, 07:10 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
yes, i built the application, a * .jar file is running on second machine.
- 05-17-2010, 07:11 AM #4
It looks rather like you might be making calls to Swing methods off of the EDT. To get better help sooner, post a SSCCE *
* SSCCE : Java Glossary
db
- 05-18-2010, 07:47 AM #5
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
what is this SSCCE ? i have no idea.
- 05-19-2010, 04:01 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Means this.
Did you go through the link that Darryl post in his last post? Click on the second result on that page and read it.Short Self-Contained Compilable Example
- 05-19-2010, 04:01 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 05-19-2010, 04:37 AM #8
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
no, i didn't get any error messages..
- 05-19-2010, 02:45 PM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
So then post what you've done here to check.
- 05-26-2010, 11:07 AM #10
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
here is the code i tried..Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * SimplePrint.java * * Created on Jan 11, 2010, 4:29:16 PM */ package home.tess.ukw; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.ActionListener; import java.awt.print.*; import javax.swing.JFrame; import javax.swing.JOptionPane; /** * * @author uthpalaw */ public class SimplePrint extends javax.swing.JFrame implements Printable { JFrame frameToPrint; static JFrame SP = new SimplePrint(); /** Creates new form SimplePrint */ public SimplePrint() { initComponents(); } public SimplePrint(JFrame f){ frameToPrint = f; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Simple Print Form"); jLabel1.setText("Hi Diluka"); jButton1.setText("Print"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1)) .addContainerGap(361, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(51, 51, 51) .addComponent(jLabel1) .addGap(65, 65, 65) .addComponent(jButton1) .addContainerGap(132, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: // JOptionPane.showMessageDialog(null, "hello"); PrinterJob PJ = PrinterJob.getPrinterJob(); //PageFormat PF = PJ.pageDialog(PJ.defaultPage()); PJ.setPrintable((Printable) this); boolean doPrint = PJ.printDialog(); //JOptionPane.showMessageDialog(null, doPrint); if(doPrint){ try { PJ.print(); } catch (PrinterException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } }//GEN-LAST:event_jButton1ActionPerformed public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex > 0) { return(NO_SUCH_PAGE); } else { Graphics2D g2d = (Graphics2D)g; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); // Turn off double buffering //componentToBePrinted.paint(g2d); //frameToPrint.print(g); SP.print(g); // Turn double buffering back on return(PAGE_EXISTS); } } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { SP.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; // End of variables declaration//GEN-END:variables }Last edited by Eranga; 05-27-2010 at 05:56 AM. Reason: code tags added
- 05-27-2010, 05:58 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Please use code tags when you posting again here in the forum. Unformated codes are really hard to read. If you don't know how to do it, please check on my forum signature. You can find the link to the relevant page.
- 05-27-2010, 06:02 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Is this initialized properly?
Java Code:Graphics2D g2d = (Graphics2D)g; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
- 05-31-2010, 05:53 AM #13
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
no idea.... what do u suggest ?
- 05-31-2010, 05:16 PM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What I'm ask is that following values are set properly?
Java Code:pageFormat.getImageableX(), pageFormat.getImageableY()
- 06-03-2010, 08:53 AM #15
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
yes....... it's.......
- 06-09-2010, 12:31 PM #16
Member
- Join Date
- Mar 2010
- Posts
- 67
- Rep Power
- 0
Similar Threads
-
Help in Printing
By kirly in forum Advanced JavaReplies: 3Last Post: 10-03-2011, 03:40 PM -
Printing
By zzpprk in forum AWT / SwingReplies: 0Last Post: 01-20-2010, 11:25 AM -
Printing Help...
By chiragkini in forum AWT / SwingReplies: 1Last Post: 02-17-2009, 06:07 AM -
Printing issues...
By chango77745 in forum New To JavaReplies: 15Last Post: 02-14-2009, 02:01 AM -
Printing Example
By Java Tip in forum SWTReplies: 0Last Post: 07-11-2008, 04:41 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks