Span / Grow bug in MigLayout?

The following is close to what I want and does what I expect:

import javax.swing.JComboBox; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import net.miginfocom.swing.MigLayout; public class MigBug extends JFrame { public static void main(String args[]) { MigBug migbug = new MigBug(); migbug.pack(); migbug.setVisible(true); } public MigBug() { JPanel content = new JPanel(); content.setLayout(new MigLayout("fill, debug")); content.add(new JLabel("Label 1")); content.add(new JComboBox()); content.add(new JLabel("Label 2")); content.add(new JTextField(25), "growx, wrap"); content.add(new JLabel("BIG"), "span, w :400:, h :200:, growy"); setContentPane(content); } } 

However, if I make the following change:

 content.add(new JLabel("BIG"), "span, w :400:, h :200:, grow"); 

t. Change the stretched component to grow on both x and y, the core of label 1 grows at x, although it should not.

Does anyone know how I can get around this?

+4
source share
2 answers

A workaround has been found, although not entirely satisfactory. According to this forum post and this forum post , MigLayout switches from calculating component sizes and calculates the sizes of the columns in which the range is involved. Replacing “fill” with “filly” in layout constraints, adding column constraints with “grow” for each column that should be allowed for growth seems to fix it.

Work code:

 import javax.swing.JComboBox; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import net.miginfocom.swing.MigLayout; public class MigBug extends JFrame { public static void main(String args[]) { MigBug migbug = new MigBug(); migbug.pack(); migbug.setVisible(true); } public MigBug() { JPanel content = new JPanel(); content.setLayout(new MigLayout("filly, debug", "[][grow][][grow]")); content.add(new JLabel("Label 1")); content.add(new JComboBox()); content.add(new JLabel("Label 2")); content.add(new JTextField(25), "growx, wrap"); content.add(new JLabel("BIG"), "span, w :400:, h :200:, grow"); setContentPane(content); } } 
+3
source

You can also try my MatrixLayout manager as an alternative. The concept is similar to the concept of MiG Layout - table. It is not so strong, but it seems (to me, anyway) much easier to use (with great strength comes great complexity). But, to be honest, it could just be because I didn’t really try to understand the MiG layout.

+1
source

All Articles