FlowLayout would display each panel at its preferredSize. GridLayout would make them the same size, but resize both when the frame is resized, keeping a constant gap.
For the panels to display at their (possibly different) preferredSize(s) with the gap between them varying when resizing the frame, I would use a horizontal Box with horizontal glue between the panels. A minimum gap could be enforced with a horizontal strut.
GridBagLayout with appropriate anchor / fill constraints would also do the trick, but resizing smaller might result in one or both panels shrinking to the minimumSize.
There are no new questions, but there may be new answers.
posted 5 years ago
I'm almost there,
Im using a box Layout with horizontal glue as suggested by Darryl.
Looks OK apart from the 2 inner panels are still growing in size when the frame is resized (along with the gap in the middle). I just want the gap in the middle to grow / shrink
I have tried to set the preferredSize to the inner panels but it does not seem to make any difference.
Can anyone advise ?
Here is an inner panel class...
The panel has 5 buttons inside it. I want the width of the panel to be slightly longed that the combined width of the 5 buttons. I need to add 300 to do this. Not sure why ???