Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Punx

[java] Centering text

This topic is 5862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a String that I want to place in a box in my frame. Now I can manually adjust it until it looks right but then when I put a different sized string of text it''s not centered as it should be. Is there a function that can center text on an x axis? I''ve looked it setHorizontalText or something but I couldn''t get it to work right.

Share this post


Link to post
Share on other sites
Advertisement
If you are using awt you can get a FontMetrics object from the Graphics (Graphics.getFontMetrics()) object and use the FontMetrics.stringWidth(String) to get the width of the string.

Hope that helps....

:-)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!