[Date Prev][Date Next][Index][Thread] [SGT Mail Archive] [SGT Main Page]

RE: printing for dummies



*************************************************
Message from the sgt mail list.
*************************************************

Hi Patrick,

Disregard me private email to you, I've found a solution and I figured I'd 
share it for others.

This technique works well for JPlotLayout without the key pane thingee.

	...
        JPlotLayout ltsl;
        ...
        PrinterJob p = PrinterJob.getPrinterJob();
        p.setPrintService(PrinterJob.lookupPrintServices()[1]);
        PageFormat pf = p.defaultPage();
        pf.setOrientation(pf.LANDSCAPE);
        Printable adapter = new Printable() {
            public int print(Graphics g,PageFormat pf,int page) {
                if (page > 0) return Printable.NO_SUCH_PAGE;
                Graphics2D g2 = (Graphics2D) g;
                int width = ltsl.getWidth();
                double scale = pf.getImageableWidth() / width;
                int tx = (int) pf.getImageableX();
                int ty = (int) pf.getImageableY();
                g2.translate(tx,ty);
                g2.scale(scale,scale);
                ltsl.draw(g2);
                return Printable.PAGE_EXISTS;
            }
        };
        p.setPrintable(adapter, pf);
        p.print();

In this example I simply hardcoded the printer parameters because I was 
testing it and tired of navigating through the printer dialog. But you can 
easily do the same using the dialog.

Regards,
Ian


*************************************************
To remove yourself from this mailing list,
send mail to <Majordomo@epic.noaa.gov> with
"unsubscribe sgt" in the message body.