p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Java GUI (http://p2p.wrox.com/forumdisplay.php?f=115)
-   -   Repositioning Top Left Corner of a Page in print (http://p2p.wrox.com/showthread.php?t=33874)

dontknowmuch September 30th, 2005 12:05 PM

Repositioning Top Left Corner of a Page in print
Edit on Oct 6:

I find out the cause of my problem. The soluation is using the "PageFormat" method, setPaper(Paper paper), to set the modified paper and it works. Thanks for those who read it.

Good Morning,

I need help on the re-positioning of the top left corner (of the Imageable X-Y) of a page for the printing of a table data. According to the API class java.awt.print.Paper, one can use the method setImageableArea( double x, double y, double width, double height) to set the X-Y. (By the way I am using V1.42 of the J2SE)

The part of the code to do the change of the X-Y is shown:

public int print (Graphics g, PageFormat pf, int idx)
    throws PrinterException
// Printable's method implementation


// First get the Origin values
Paper objPa = new Paper( );
double dX = objPa.getImageableX();
double dY = objPa.getImageableY();
double dW = objPa.getImageableWidth();
double dH = objPa.getImageableHeight();
// Print the values before changing (show 72 or 1 inch for both X-Y)
System.out.println("\n ORIGINAL X-Y Width & Hieght = " + dX +", " + dY
+", " + dW + ", " + dH);

// now change the X-Y to 36 or 1/2 inch
objPa.setImageableArea( (Dx/2.0), (dY/2.0), dW, dH );
dX = objPa.getImageableX();
dY = objPa.getImageableY();
// Print the Altered values after changing (show 36 or 1/2 inch)
System.out.println("\n CHANGED X-Y Width & Hieght = " + dX +", " + dY
+", " + dW + ", " + dH);



However the top left corner of the paper (of the printed page) still has 1x1 inch as if there is no change at all. I had move the codes around in different part of the program but still shows 1X1 inch! I MUST DOING SOMETHING WRONG? Can someone help? Thank you.

All times are GMT -4. The time now is 02:06 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.