I have a dynamic java Swing form UI that needs to resize when a toggle button is pressed. Components inside the form panel need to be removed or added and the height accordingly reduced/increased.
Cardlayout allows me to switch between two panels with different components but the height is hardwired to the the tallest card. I need to dynamically remove swing components and reduce the height of the inner panels as well as the entire main panel.
Using Grouplayout with setHonorsVisibility(true) doesn't work either unless the entire layout hierarchy is re-created. There is no way to get rid of the gaps between components being hidden.
BoxLayout may sort of works but with a box container it will be a pain to layout the form elements to align nicely. So I haven't tried it.
I would like to work with Netbeans GUI builder if possible but the default GroupLayout doesn't work for me. So looking at other design patterns/strategies to solve this.
I would hate to manually setPreffered dimensions on nested panels.
How to people deal with re-packing the UI after removing components ?