mikaelgrev/miglayout

Inconsistent column/row gaps with empty columns/rows

Closed this issue · 6 comments

If a layout has empty columns/row, then there is an inconsistency in computing column/row gaps depending on whether column/row constraints are specified or not.

Here is a program that demonstrates the difference:

public class GapMergeTest
{
    public static void main(String[] args)
    {
        JPanel panel1 = new JPanel(new MigLayout("debug"));
        panel1.add(new JLabel("cell 0 0"), "cell 0 0");
        panel1.add(new JLabel("cell 0 2"), "cell 0 2");

        JPanel panel2 = new JPanel(new MigLayout("debug", "", "[][][]"));
        panel2.add(new JLabel("cell 0 0"), "cell 0 0");
        panel2.add(new JLabel("cell 0 2"), "cell 0 2");

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add( panel1, BorderLayout.WEST );
        frame.getContentPane().add( panel2, BorderLayout.EAST );
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

gapmergetest

The left panel does not have column constraints and the gap between the two visible rows is as expected a single "rel".

The right panel has column constraints "[][][]", but the gap between the two visible rows is 2x "rel".

Is this correct behaviour?
Feels confusing to me...

Good catch! I've pushed a fix and added the "test" class to the Swing code.

Thx for the quick fix, but it seems that gaps are now no longer computed as described in the whitepaper:

Generally gaps are not added; instead they are considered to be the minimum space a component/cell wants to the components/cells around, this is consistent with how humans would define spacing. If for instance one component have a gap of 10 pixels after it and the next component has specified a 20 pixel gap before it, the resulting gap is 20 pixels and not 30.

Thought that the left panel in the above example was correct and the right one wrong. But now both look like the right one.

I would expect that gaps of empty columns/rows (or columns/rows that contain only invisible components and hidemode is 3) are completely ignored (as in the left panel). This has the advantage that I can remove or hide components at runtime and the gaps are computed automatically.

Here is an example. On the left the complete form. On the right the "property name" components are invisible, but now the gap between the "Listener method" and "Handler method" rows is too large. (was OK before the fix)

2015-10-09_15-10-19

I understand. The third example I added also does the same as the right panel. So the left one was the odd one out. Removing the empty rows/columns does (I believe) change more stuff and would break more old layouts. And it seems quite logical to me to have empty rows take up space, since one can always choose to not add empty rows. Removing empty rows means that the option to use that for spacing disappears. And the paragraph starts with "Generally..." :)

But if you want to change it to the way you want, you can do it with my blessing. But then there should probably be a global/static switch to get the old behaviour back for all layouts.

OK, many thx. I'll check what I can do...

Is there any update on this?
How does one dynamically "hide" certain rows without leaving a "double" gap when having specified cell positions and layout row constraints?