I am working on dynamic layouts: I want to use a layout which requires the container to expand as requested by the elements contained.
This is because I have "growing" widgets (I implemented text fields which grow or shrink as the text is added or deleted) and I can also add or remove dinamically widgets.

I wonder which is the best way to implement it.

I tried forcing the layout application on the parent of the container:


It apparently works but it very slow,

I have not a lot of experience with Swing, do you know of alternatives way to achieve this?

Thank you,