I have a JPanel parent with 3 JPanel children inside. They all currently make use of GridLayout and together represent a UML class. Problem is that when I add a new attribu
I suggest you to use BoxLayout. Here's a tutorial. Playing around with glues and rigid area you can obtain almost all desired layout. In your case the code should be somthing like this:
JPanel container = new JPanel();
container .setLayout(new BoxLayout(container , BoxLayout.Y_AXIS));
JPanel childTop = new JPanel();
JPanel childCenter = new JPanel();
JPanel childBottom = new JPanel();
childTop.setMaximumSize(...);
childBottom.setMaximumSize(...);
container.add(childTop);
container.add(Box.createVerticalGlue());
container.add(childCenter);
container.add(Box.createVerticalGlue());
container.add(childBottom);
When you need to insert a new child, remember to insert it into the right position: between one of the glues and childCenter. For example:
container.add(newChild, 2) ;