From: beowolf on 5 Jul 2010 02:43 I'm trying to print a "book" of two tables, each table has 3 pages. Heres the code: Printable jtp1= jTable1.getPrintable(JTable.PrintMode.FIT_WIDTH , new MessageFormat("jTable1"),null) ; Printable jtp2= jTable2.getPrintable(JTable.PrintMode.FIT_WIDTH , new MessageFormat("jTable2"),null) ; PrinterJob job = PrinterJob.getPrinterJob(); PageFormat portrait = job.defaultPage(); portrait.setOrientation(PageFormat.PORTRAIT); Book bk = new Book(); bk.append(jtp1, portrait,3); bk.append(jtp2, portrait,3); job.setPageable(bk); if (job.printDialog()) { try { job.print(); } catch (Exception exc) { } } Unfortunately it only prints table1 (jtp1). I've googled like a fool, but i've not found anything relevant to this problem: can anybody help me ? Thank you
From: John B. Matthews on 5 Jul 2010 20:40 In article <82d9b2e0-f6ca-4440-a813-1f6ec82dd7b0(a)d8g2000yqf.googlegroups.com>, beowolf <michiedo(a)email.it> wrote: > I'm trying to print a "book" of two tables, each table has 3 pages. > Heres the code: > [...] > Unfortunately it only prints table1 (jtp1). I've googled like a fool, > but i've not found anything relevant to this problem: can anybody > help me ? The table's getPrintable() will only image the visible part of the component, anyway. For a multi-page table, consider one of print() methods of JTable: <http://java.sun.com/javase/6/docs/api/javax/swing/JTable.html> Alternatively, see "Components Larger Than One Page": <http://java.sun.com/developer/onlineTraining/Programming/JDCBook/advprint.html> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
From: Christian Kaufhold on 13 Jul 2010 16:35 beowolf <michiedo(a)email.it> wrote: > I'm trying to print a "book" of two tables, each table has 3 pages. Are you sure of exactly 3 pages? How do you know? > Heres the code: [...] > > Unfortunately it only prints table1 (jtp1). Book is broken, mainly because it hands out the original printable, which means 1. The page indices will be wrong for anything but the first contained Printable (i.e. your second JTable is trying to print its own pages 3 - 5, which do not exists). 2. NO_SUCH_PAGE will be returned too early, even if the book itself has still more pages. Basically it only works for single-page Printables (which ignore the pageIndex argument and always return PAGE_EXIST): Just write your own minimum Printable/Pageable implementation that wraps the inner Printables properly.
|
Pages: 1 Prev: Best class decompiler? Next: Struts - Lazy Validator Form |