
Re: Add feature: MiGLayout to behave like Wrap Layout?
Hi,
My reply is mainly addressed to MiGMaster. Currently, I am facing the exact same problem as the one you described in your first post in this forum. I was hoping (too) that the existence of "WrapLayout" (which seems to be working well) would motivate MigLayout to eventually support flowing layouts.
First of all, could you please tell us what method did you eventually adopt? Did you eventually use WrapLayout within MigLayout?
Also, I would like to point to the following:
1. I agree with you that using WrapLayout instead of FlowLayout (as demonstrated in your MiGTest example) solves the problem "when placing the flowing layout in the north section of a BorderLayout", which was raised by Mikael (MiG Support).
2. I agree that WrapLayout works fine when used inside MiGLayout, however for it to work in your example, it is not enough to just switch the comments on the lines:
Code:
setLayout(new BorderLayout());
//setLayout(new MigLayout("debug, fillx", "[fill]"));
as you described. If you only do that, wrapping will work fine only if you're resizing the frame in very small increments. As soon as you resize it "in one big shot", you will notice how part of the content of the frame will disappear (and hence wrapping won't work properly).
For it to work properly, one way is to add the panel inside a scrollpane, i.e. in your code, instead of directly adding jPanel, add new JScrollPane(jPanel). Now, wrapping should work properly. Do you agree with me on this point?
3. So far JScrollPane solved our problem, as long as the container in its viewport had only one child. The example below puts two child panels inside the root panel contained in the scrollPane. In this case, again, unless if you're resizing the frame in very small increments, wrapping won't work properly.
Code:
public class MiGTestModified extends JFrame {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
new MiGTestModified().setVisible(true);
}
public MiGTestModified() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(700, 400);
JPanel rootPanel = new JPanel(new MigLayout("debug, fill", "[fill]", "[fill]"));
JScrollPane scrollPane = new JScrollPane(rootPanel);
JPanel panelA = new JPanel(new WrapLayout());
for (int i = 0; i < 10; i++) {
panelA.add(new JButton("" + i));
}
JPanel panelB = new JPanel(new WrapLayout());
for (int i = 0; i < 10; i++) {
panelB.add(new JButton("" + i));
}
rootPanel.add(panelA, "cell 0 0");
rootPanel.add(panelB, "cell 0 1");
getContentPane().add(scrollPane);
}
}
However, if you set the layout of rootPanel to BorderLayout, and you use say BorderLayout.NORTH and BorderLayout.SOUTH for panelA and panelB, WrapLayout works normally.
Hence, it seems that mixing WrapLayout within MigLayout is not that safe!
Feedback from MiG Support is also highly appreciated.
Thank you,
Shant