How can I make MiGLayout behave like a Wrap Layout?

I would like to repeat the example shown here:

Wrap layout

Using MiGLayout. I tried some combinations, but it's hard for me to make the buttons automatically wrap to new lines when the container is compressed.

Can anyone provide a working example doing this?

Here is the shell for the program:

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 < 10; i++) { jPanel.add(new JButton("" + i)); } } } private void initComponents() { jPanel = new JPanel(new MigLayout("debug")); jButton = new JButton("Test"); } } 
+6
source share
2 answers

I declare .width ("xx%") and then call wrap when the line width is up to 100%. This works if you can declare each component a specific percent of the string (they do not all have to be one percent).

0
source

Source: https://habr.com/ru/post/886234/


All Articles