Lana,
You don't say what release of Java 2 you are using, or on which
platform, but I don't recall quite the problem you describe on
any release or platform. Its unlikely your printer allows zero
margins but you should be able to adjust them to less than an inch.
Although I can't spot the problem from your description, I would
have to guess that you are missing a step somewhere.
Perhaps you aren't setting the PageFormat on the printable?
Try the attached program and see what you get.
It draws a box slightly within 1/2" margins which ought to be
achievable on most printers.
-Phil.
> Date: Thu, 3 Feb 2000 08:02:39 -0800
> From: Lana <[EMAIL PROTECTED]>
> Subject: [JAVA2D] Printing-setImageableArea()???
> To: [EMAIL PROTECTED]
>
> I am trying to get rid of the 1 inch margins on my printed paper. I have created a
new paper and set the page format to this new paper. I also used the
setImageableArea(0.0,0.0,612.0,792.0); but no luck. What else can I do??? I even
redefined my page size(I am just using standard 8.5 by 11), just to be sure. This is
the only way that I have read about to change the margins in the code. I have used
the getImageableHeght() to print the value. It is telling me the right numbers, but
just not allowing me to print in that 1 inch margin surrounding the page. I am
implementing Printable. Any help would be greatly appreciated.
>
> Thank you,
> Lana
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
import java.awt.*;
import java.awt.print.*;
public class PrintMargins3 implements Printable {
public static void main( String[] args) {
PrintMargins3 pm = new PrintMargins3();
}
public PrintMargins3() {
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat pf = pj.defaultPage();
Paper p = new Paper();
// set 1/2" margins on paper
p.setImageableArea(36, 36, p.getWidth()-72, p.getHeight()-72);
// set paper into pageformat
pf.setPaper(p);
// set pageformat into printable
pj.setPrintable(this, pf);
try {
pj.print();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
if (pageIndex > 0) {
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D)graphics;
System.out.println("ix=" + pageFormat.getImageableX() +
" iy="+pageFormat.getImageableY());
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
g2d.setColor(Color.black);
g2d.drawString("ORIGIN", 20, 20);
g2d.drawString("X THIS WAY", 200, 50);
g2d.drawString("Y THIS WAY", 60 , 200);
g2d.drawRect(5,5,(int)pageFormat.getImageableWidth()-10,
(int)pageFormat.getImageableHeight()-10);
return Printable.PAGE_EXISTS;
}
}