Swing layout with miglayout and nested panels
Posted
by
Jazzepi
on Stack Overflow
See other posts from Stack Overflow
or by Jazzepi
Published on 2012-09-11T21:35:52Z
Indexed on
2012/09/11
21:37 UTC
Read the original article
Hit count: 489
I have a Swing program using SwingLayout. The structure of the Swing components looks like this.
JFrame
JPanel (Cardlayout)
JPanel (Miglayout) - Main panel
Jpanel (Flowlayout) - Checkbox Panel
JPanel (Flowlayout) - Option Panel
My problem right now is that I'm not sure how to prevent the checkbox panel from growing. I don't want it to "push" out the column that it's in to the right. I want Wraplayout (which works fine on the option panel) to wrap the content of the checkbox panel when it grows too big.
This is the view of it from the Windowsbuilder GUI inside of Eclipse. The panel with the label "sites" in it is the Checkbox Panel. Directly to the right of the Checkbox panel is the Option panel. The big panel containing both of them is the main panel. http://i.imgur.com/S7Njo.png
This is what happens when I add too many checkboxes http://i.imgur.com/f2SZz.png
My main problem is that I don't understand why setting "grow 0" on the column constraint for the first column in mainpanel doesn't prevent it from growing when the component inside gets too big as I add new checkboxes to the site panel (the site panel can have an arbitrary number of checkboxes).
This is my miglayout for the main panel.
mainPanel.setLayout(new MigLayout("", "[][grow]", "[][][][][][][][grow]"));
Here are my component constraints for when I add the checkbox panel
siteCheckBoxPanel = new JPanel();
mainPanel.add(siteCheckBoxPanel, "cell 0 0,alignx left,gapx 0px,aligny center");
siteCheckBoxPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
I've also tried it without flow layout, and that doesn't fix anything. Any insight you could provide would be great! I'm also happy to provide more information if people have questions. FYI I've also tried "grow 0" on both the column and row constraint for the cell that the Checkbox Panel is inside.
© Stack Overflow or respective owner