[java] Centering text

Started by
2 comments, last by Punx 21 years, 10 months ago
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.
~punx
Advertisement
If there isn''t one, just get the width and divide by two.
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....

:-)
ujhkfkfk
Use a Layout and use the appropriate contraint.

D-

-----------
Érdely!
-----------Érdely!

This topic is closed to new replies.

Advertisement