Button with dynamic label inside

Hi all,
I’m trying to do a button with a dynamic textfield inside, and I want the button to resize according to the size of the textfield.
I could create a textfield with createTextField, but the problem is that in that case I’d need to give it the size of the text, that I don’t know beforehand.
How could I know that? Did anyone have the same problem?