Reputation: 4281
I have a bottomPanel, and I want to add two panels side by side into this panel. They are bottomLeft and bottomRight panel. So I'm thinking if I set the minimum size of outter panel larger than the width when they are side by side, when I make the window smaller, the two panels should maintain side by side. But bottomRight always goes under bottomLeft. Below is the code and I use flowLayout for bottomPanel.
bottomPanel.add(bottomPanelRight);
bottomPanel.add(bottomPanelLeft);
bottomPanel.setMinimumSize(new Dimension(600, 600));
Upvotes: 0
Views: 600
Reputation: 347184
The immediate issue seems to be the fact the the default layout of a JPanel
is FlowLayout
(since I can't see any code changing the layout)
Try using a GridLayout
. This will ensure that both the components are given equal space within the container, meaning that they will change size as the parent container changes size.
Use a GridBagLayout
, which will provide you greater ability to determine how each component is laid out within their given cells.
GridBagLayout
will, if not told to do otherwise, use the preferred size of the components. If there is not enough space to honour the preferred size, it will use the components minimum size instead
Take a look at Laying Out Components Within a Container for more details
Upvotes: 1