MigLayout error: "Unstable circular dependency in absolute bound values!"

Why this SSCCE (with MigLayout libraries) ...

public static void main(String[] args) {

    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }

    JFrame frame = new JFrame();
    frame.setLayout(new MigLayout(new LC().fill().insetsAll("0")));

    JTabbedPane jtp = new JTabbedPane();
    jtp.add(new JPanel(), "Tab 1");
    jtp.add(new JPanel(), "Tab 2");

    JLabel label = new JLabel("label");

    JPanel panel = new JPanel(new MigLayout(new LC().fill()));
    panel.add(jtp, "id tabbedpane, grow, span");
    panel.add(label, "pos (tabbedpane.w-label.w) 10, id label");
    label.setBounds(100, 100, 10, 10);

    frame.add(panel, "grow, span");
    frame.setSize(500, 500);
    frame.setLocationRelativeTo(null); // Sorry, Andrew Thompson
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

      

Throw this error:

Unstable cyclic dependency in absolute linked values!
Unstable cyclic dependency in absolute linked values!
Unstable cyclic dependency in absolute linked values!
Unstable cyclic dependency in absolute linked values!

      

?

I realized that if you remove the code WindowsLookAndFeel

then everything will be fine ...

enter image description here

So this is a problem with MigLayout and WindowsLookAndFeel

. However, my real application requires using it.

EDIT:

This is what the frame looks like on error:

enter image description here

+3


source to share


1 answer


Taking a look at the source code , it does this as it makes adjustments to the size of the components when the layout is executed. If it does more than count * 8 + 10 corrections, then it closes the code to prevent an infinite loop.

Relevant source (with some material removed):

do {
    doAgain = false;
    for (Iterator<Cell> it = grid.values().iterator(); it.hasNext();) {
        ArrayList<CompWrap> compWraps = it.next().compWraps;
        for (int i = 0, iSz = compWraps.size(); i < iSz; i++) {
            CompWrap cw = compWraps.get(i);

            if (j == 0) {
                doAgain |= doAbsoluteCorrections(cw, bounds);
                // . . .
            }

            // . . .
        }
    }
    clearGroupLinkBounds();
    if (++count > ((compCount << 3) + 10)) {
        System.err.println("Unstable cyclic dependency in absolute linked values!");
        break;
    }

} while (doAgain);

      



So what happens if doAbsoluteCorrections returns true (which it does if any components change size when patches are made to satisfy the sizing dependencies), then it will loop over, which patches again. What you see is the warning message it prints when it is repeated too many times. Since fixes can cause related components to resize, you can get a situation where fixes will override the y-value for one component and set the y-value for the other, then when that first component has a y-value set, it overrides the y-value for the other. and this is repeated until we finish trying.

Windows L&F caused this problem very often for me because it seemed like the components would always be consistent with the situation where they would make this correction and only change 1 pixel to fix, but this correction caused it to be necessary to redo the layout of another component. which made it slide 1 pixel back. "Recursion" (if you want to think so) was unstable and did not reach a stable solution.

I don't know what the solution is for deleting these messages, but if it doesn't cause unusual "laughs" in your application (you know what I mean if it does), I wouldn't bother with that. It's just a message indicating that it is discarding fixes because it is being repeated too many times.

+3


source







All Articles