Centering

F

freesoft_2000

Hi everyone,

I am trying to center a page number on the bottom center
on a printed page but i am having some trouble doing it.

I am using the windows default page dialog where the user can select the
desired page size(ie, a1,a2,a4) but i am unable to center the page number
on the bottom center.

For now i am using hard-coded values but these values only work for the a4
paper format.

Code:
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)

{
//other codes
//other codes

Font f = new Font("Arial", Font.PLAIN, 12);
graphics2D = (Graphics2D) graphics;
graphics2D.setFont(f);

graphics2D.drawString(("Page " + (pageIndex + 1)), 223, 643);

}

I know centering the page number involves the FontMetrics class but i
can't seem to get it right. What i would like is for the user to select
any page format using the windows page dialog and the page number is drawn
on the bottom center of the page when it is printed

I hope someone can help me with this problem

Thank You

Yours Sincerely

Richard West
 
B

Birkemose

...
For the future: Please don't multi-post the same question in different
groups; consider cross-posting instead. Read
http://www.physci.org/codes/javafaq.jsp#xpost for the reason why.

I dont see any reason ( even after reading the above link ) why crossposting
should be better than multi posting...
Some hate cross-posting, some dont, some hate top posting some dont....

I personally think is should be left to the poster....

In this case, where I include a small amount of the original post, I will
add my answer to the bottom, to keep a flow in reading...
If the part of the original message I included, was more like an apendix, or
FYI only, I would add it after my comment....

But bottom line, it is my choice..
 
V

Virgil Green

Birkemose said:
...


I dont see any reason ( even after reading the above link ) why
crossposting should be better than multi posting...
Some hate cross-posting, some dont, some hate top posting some
dont....

Crossposting creates, in theory, a single conversation whereas multi-posting
creates multiple conversations. The latter becomes counter-productive.
I personally think is should be left to the poster....

As it will be left to the potential responders (the really nice people who
try to help others for free) to ignore those people who continue to insist
on doing things *their* way rather than being willing to fit in with the
culture.
But bottom line, it is my choice..

This, indeed, is true. And the consequences (typically being ignored after a
time) will also be yours.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top