Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to print a JPanel

 
Michael Bell
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a GUI which has a JTable and JPanel. The JPanel contains labels and textfields. The JTable is easily printed using the new print() method.
Can the JPanel be printed without having to implement Printable as I am using Netbeans IDE and do not wish to redo all my work?
[ January 24, 2006: Message edited by: Michael Bell ]
 
Michael Bell
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setJobName("Subscriber Details for Msisdn=");
pj.setCopies(1);
PageFormat format = pj.defaultPage();
format.setOrientation(PageFormat.LANDSCAPE);

pj.setPrintable(new Printable() {
public int print(Graphics pg, PageFormat pf, int pageNum){
if (pageNum > 0){
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) pg;
g2.translate(pf.getImageableX(), pf.getImageableY());
jPEdit.paint(g2);
return Printable.PAGE_EXISTS;
}
});
if (pj.printDialog() == false)
return;

pj.print();
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic