java - why is jtable output is not printing on the paper? -


i have populated jtable database below.![enter image description here][1] trying send output printer.but when click on print button ,output on paper not correct.

i haved used method.

1.actionlistener

btnprint.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) {             printerjob pjob = printerjob.getprinterjob();             pageformat preformat = pjob.defaultpage();             preformat.setorientation(pageformat.landscape);             pageformat postformat = pjob.pagedialog(preformat);             //if user not hit cancel print.             if (preformat != postformat)              {                 //set print component                 pjob.setprintable(new printer(table), postformat);                 if (pjob.printdialog()) {                     try {                         pjob.print();                     } catch (printerexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                     }                 }             }         }     }); 

2.printer class

    import java.awt.component;     import java.awt.dimension;     import java.awt.graphics;     import java.awt.graphics2d;     import java.awt.print.pageformat;     import java.awt.print.printable;     import java.awt.print.printerexception;      public class printer implements printable {     final component comp;      public printer(component comp){         this.comp = comp;     }      @override     public int print(graphics g, pageformat format, int page_index)              throws printerexception {         if (page_index > 0) {             return printable.no_such_page;         }             // bounds of component         dimension dim = comp.getsize();         double cheight = dim.getheight();         double cwidth = dim.getwidth();             // bounds of printable area         double pheight = format.getimageableheight();         double pwidth = format.getimageablewidth();             double pxstart = format.getimageablex();         double pystart = format.getimageabley();             double xratio = pwidth / cwidth;         double yratio = pheight / cheight;         graphics2d g2 = (graphics2d) g;         g2.translate(pxstart, pystart);         g2.scale(xratio, yratio);         comp.paint(g2);             return printable.page_exists;     }        } 


Comments