This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to print a JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to print a JPanel" Watch "How to print a JPanel" New topic

How to print a JPanel

Michael Bell

Joined: Dec 05, 2005
Posts: 19
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

Joined: Dec 05, 2005
Posts: 19
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setJobName("Subscriber Details for Msisdn=");
PageFormat format = pj.defaultPage();

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());
return Printable.PAGE_EXISTS;
if (pj.printDialog() == false)

rocket mass heater kickstarter
subject: How to print a JPanel