You can determine the width an height of a string using the FontMetrics class.
An instance of FontMetrics can be acquired using the getFontMetrics method on component.
You should pass the font that you are using to paint on you component (getFont). Then you can use the getStringBounds method to calculate the width and height of a string.
I do not know if this helps you out but it answers the question in your message header.