How can I make MiGLayout behave like Wrap Layout?

admin

Administrator
Staff member
I'd like to replicate the example shown here:

<A href="http://tips4java.wordpress.com/2008/11/06/wrap-layout/" rel="nofollow noreferrer">Wrap Layout</a>

Using MiGLayout. I have tried some combinations, but I'm
having a hard time making the buttons wrap automatically
to new rows as the container shrinks.

Could someone please provide a working example doing this?

Here is a shell for the program:

Code:
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;

public class MiGTest extends JFrame{
    private JPanel jPanel;
    private JButton jButton;

    public static void main(String[] args) {
        new MiGTest().setVisible(true);
    }

    public MiGTest(){
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new MigLayout("debug"));

        initComponents();
        addComponents();
        pack();
    }


    private void addComponents() {      
        add(jPanel);{
            for (int i = 0; i &lt; 10; i++) {
                jPanel.add(new JButton("" + i));
            }
        }
    }

    private void initComponents() {
        jPanel = new JPanel(new MigLayout("debug"));
        jButton = new JButton("Test");  
    }
}