Too many JPanels inside a JPanel (with GridBagLayout)
问题 So basically if I put JPanel s inside a JPanel that uses GridBagLayout and I restrict the size with setPreferredSize , eventually it reaches a point where it can't hold all of them, and it exhibits the behavior shown in the attached picture: I'm making an accordion. This is just an example to showcase the problem I'm having. Each part of the accordion can open individually and they're of arbitrary size and get added on the fly. Its easy enough to get the heights of all the individual panels