Search the web
Sign In
New User? Sign Up
jsci
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
problem with print   Message List  
Reply | Forward Message #142 of 369 |
I want to print a JlineGraph on the printer.

I have problems with the scaling : The graph will be printed
in 2 or 3 pages instead of 1.

I am using the utility class from Martin Hall (see below):

Have you tried printing and how ?

thank you

Christopher



public class PrintUtilities implements Printable {
private Component componentToBePrinted;
private int index ;
public static void printComponent(Component c) {
new PrintUtilities(c).print();
}

public PrintUtilities(Component componentToBePrinted) {
this.componentToBePrinted = componentToBePrinted;
index=0;
}

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) {
if (index > 0) {
return(NO_SUCH_PAGE);
} else {
index ++;
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(c);
currentManager.setDoubleBufferingEnabled(false);
}

public static void enableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);
}
}









Mon Aug 9, 2004 1:33 pm

christophean...
Offline Offline
Send Email Send Email

Forward
Message #142 of 369 |
Expand Messages Author Sort by Date

I want to print a JlineGraph on the printer. I have problems with the scaling : The graph will be printed in 2 or 3 pages instead of 1. I am using the utility...
christopheandreoli
christophean...
Offline Send Email
Aug 9, 2004
1:33 pm

Try scaling the Graphic to the page size. You can find some example code at http://java.sun.com/products/java-media/2D/forDeve lopers/sdk12print.html (Try...
Mark
mj_hale
Offline Send Email
Aug 19, 2004
7:48 am

Hello Mark, thank you. It worked nice Christopher ... Try scaling the Graphic to the page size. You can find some example code at ...
christophe andreoli
christophean...
Offline Send Email
Aug 31, 2004
11:27 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help