Results 1 to 2 of 2

Thread: put drawString in the center

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Location
    Jutland, Denmark
    Posts
    71

    put drawString in the center

    I have the following line i my code.
    page.drawString("Distance: " + dist + " pixels", 50., 50);
    How can I plase this text so it always is in the center of the applet.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I had an example somewhere, but I can't find it right now. I do know that int the paint method, you use a FontMetrics object to find the String's width. Then you use the getBounds method of the applet to get the width and height. You can divide the 2 in half to find the center.

    If I find the actual code, I'll post it. It's not tough.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width