Guest User

Untitled

a guest
Jan 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. PrinterJob job = PrinterJob.getPrinterJob();
  2. job.setJobName("test");
  3.  
  4. job.setPrintable (new Printable() {
  5. @Override
  6. public int print(Graphics pg, PageFormat pf, int pageNum) throws PrinterException{
  7. if (pageNum > 0){
  8. return Printable.NO_SUCH_PAGE;
  9. }
  10.  
  11.  
  12. Graphics2D g2 = (Graphics2D) pg;
  13. g2.translate(pf.getImageableX(), pf.getImageableY());
  14. jPanel1.print(g2);
  15.  
  16. // jTable1.print(JTable.PrintMode.FIT_WIDTH, null, null);
  17. return Printable.PAGE_EXISTS;
  18. }
  19. });
  20. boolean ok = job.printDialog();
  21. if (ok) {
  22. try {
  23. job.print();
  24. } catch (PrinterException ex) {
  25.  
  26. }
  27. }
Add Comment
Please, Sign In to add comment