Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes Centering Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Centering" Watch "Centering" New topic


Richard West
Ranch Hand

Joined: Jan 07, 2005
Posts: 127
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.

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
Lionel Badiou
Ranch Hand

Joined: Jan 06, 2005
Posts: 140
Hello Richard,

Try this :

Hope that helps,

Lionel Badiou
CodeFutures Software
Lionel Badiou
Ranch Hand

Joined: Jan 06, 2005
Posts: 140
That should center testString in the page but you may want to set height to bounds().height - x.

I agree. Here's the link:
subject: Centering
jQuery in Action, 3rd edition