Hi all,
Can anyone show me an example/codes of how to print a JFrame and its components?
Thanks.
Print JFrame in Java
Print JFrame in Java
|
|
Sep 19 2008, 07:28 PM, updated 18y ago
Show posts by this member only | Post
#1
|
![]()
Junior Member
41 posts Joined: Oct 2006 |
Hi all,
Can anyone show me an example/codes of how to print a JFrame and its components? Thanks. |
|
|
|
|
|
Sep 19 2008, 07:45 PM
Show posts by this member only | Post
#2
|
![]()
Junior Member
41 posts Joined: Jan 2005 |
extend the JFrame component from you class will do...
|
|
|
Sep 19 2008, 07:59 PM
Show posts by this member only | Post
#3
|
![]()
Junior Member
41 posts Joined: Oct 2006 |
pengkiat - I already did..
Here's the codes I found from the Internet and it only prints top left of my JFrame in one whole page. How do I make it to print the whole JFrame? QUOTE import java.awt.*; Anyone can help or where I should modify? Thanks.import javax.swing.*; import java.awt.print.*; public class PrintUtilities implements Printable { private Component componentToBePrinted; public static void printComponent(Component c) { new PrintUtilities©.print(); } public PrintUtilities(Component componentToBePrinted) { this.componentToBePrinted = componentToBePrinted; } public void print() { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(this); if (printJob.printDialog()) try { printJob.print(); } catch(PrinterException pe) { System.out.println("Error printing: " + pe); } } public int print(Graphics g, PageFormat pageFormat, int pageIndex) { if (pageIndex > 0) { return(NO_SUCH_PAGE); } else { Graphics2D g2d = (Graphics2D)g; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); disableDoubleBuffering(componentToBePrinted); componentToBePrinted.paint(g2d); enableDoubleBuffering(componentToBePrinted); return(PAGE_EXISTS); } } public static void disableDoubleBuffering(Component c) { RepaintManager currentManager = RepaintManager.currentManager©; currentManager.setDoubleBufferingEnabled(false); } public static void enableDoubleBuffering(Component c) { RepaintManager currentManager = RepaintManager.currentManager©; currentManager.setDoubleBufferingEnabled(true); } } |
|
|
Sep 20 2008, 04:28 PM
Show posts by this member only | Post
#4
|
![]() ![]()
Junior Member
113 posts Joined: Oct 2007 |
only prints top left of my JFrame in one whole page?? not too understand.. try to set your JFrame size to bigger size, it works?
|
|
|
Sep 20 2008, 06:52 PM
Show posts by this member only | Post
#5
|
![]()
Junior Member
41 posts Joined: Oct 2006 |
|
|
Topic ClosedOptions
|
| Change to: | 0.0165sec
0.21
5 queries
GZIP Disabled
Time is now: 5th December 2025 - 07:03 AM |