Getting the width of a text render can be an expensive operation, enough that if you fit it in to a box of, say, 500 pixels and it has more than 30 lines, you may see a drop in framerates.
You can curb that by creating a cache representing each line and its text width. Then you would only have to take a speed hit when you need to update the data.
The most flexible method I've come up with so far is to spit the text into words, and have a structure that contains the word and it's width. That way you can freely change the width of your box without a speed cost. Also, changing a single word would only require a change to a word-width pair of a single element. You would need to create your own justify function with this method, but it's not difficult.
However, this method has a few holes, but none that I've had to actually deal with in real applications.