Create a label
Set the background and foreground colour to your screen's background colour and the font etc to the same as the text you want to measure
Put the label in a horizontal panel
Add the horizontal panel to the root panel
Set the horizontal panel's z index behind everything else
Put the text in the label
Read the width with getOffsetWidth()
Ian