Windows - Size fit content

I’m creating windows with variant content and want the windows to fit the content in size - how do I realize this?
There does not seem to be a ready-to-use method if I follow the documentation.

Yes, you need to count content size manually and use method setDimension to set width and height (do not forget about border sizes, method setDimension sets general window’s dimention)