MigLayout错误:“绝对链接值中的不稳定循环依赖性!” [英] MigLayout error: "Unstable cyclic dependency in absolute linked values!"

查看:116
本文介绍了MigLayout错误:“绝对链接值中的不稳定循环依赖性!”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这个SSCCE(带有MigLayout库)......

Why does 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);
}

抛出此错误:

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!

我想通了如果您删除 WindowsLookAndFeel 代码,那么一切运行正常......

I figured it out that if you remove the WindowsLookAndFeel code, then everything runs fine...

因此,这是MigLayout和<$ c的问题$ C> WindowsLookAndFeel 。然而,我的真实应用程序需要使用它。

So, this is a problem with MigLayout and the WindowsLookAndFeel. Yet my real application necessitates its use.

编辑:

这是错误时框架的样子被抛出:

This is what the frame looks like when the error is thrown:

推荐答案

看一下源代码,这是因为它在组件的大小时对组件的大小进行了修正布局。如果它超过计数* 8 + 10校正,那么它会使代码短路以防止无限循环。

Taking a look at the source code, this happens as it makes corrections to the size of the components while it's doing the layout. If it makes more than count * 8 + 10 corrections, then it short circuits the code to prevent an infinite loop.

相关来源(删除了一些内容)是:

The relevant source (with some stuff removed) is:

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);

所以正在发生的事情是,如果doAbsoluteCorrections返回true(如果任何组件在更正时更改大小,则会发生这种情况)完成以满足大小依赖性)然后它将重复循环,再次进行更正。你所看到的是它重复这么多次时打印的警告信息。由于校正可能导致链接组件的大小发生变化,因此您可以获得这样的情况:更正为一个组件设置y值并为另一个组件设置y值,然后当第一个组件具有其y值时设置,它取消设置另一个的y值,这将重复,直到我们用完重试。

So what's happening is that if doAbsoluteCorrections returns true (which it does if any components change size when corrections are done to satisfy sizing dependencies) then it will repeat the loop, which does the corrections again. What you're seeing is the warning message it prints when it repeats this too many times. Since the corrections can result in changes to the sizes of linked components, you can get a situation where the corrections unset a y-value for one component and sets the y-value for the other, then when that first component has its y-value set, it un-sets the y-value for the other, and this repeats until we run out of retries.

Windows L& F经常导致此问题我,因为看起来组件总是会陷入这样一种情况,即他们会进行这种校正并且只能更改1个像素进行校正,但是这种校正导致它需要重新设置另一个组件的布局,导致它移位1像素回来了。 递归(如果你想这样想)是不稳定的,并没有达到稳定的解决方案。

The Windows L&F caused this problem very often for me because it seemed like the components would always settle into a situation where they would do this correction and only get changed by 1 pixel for the correction, but that correction caused it to need to redo the layout for another component that caused it to shift 1 pixel back. The "recursion" (if you want to think of it that way) was unstable and didn't arrive at a stable solution.

我不知道解决方案是什么是删除这些消息,但如果它不会在你的应用程序中引起异常的摇摆(你会知道我的意思,如果它),我不会担心它。这只是一条消息,表明它正在放弃更正,因为它被递归了太多次。

I don't know what the solution is to remove those messages, but if it's not causing unusual "jiggling" in your application (you'll know what I mean if it is), I wouldn't worry about it. It's just a message to indicate that it's giving up on the corrections because it's recursed too many times.

这篇关于MigLayout错误:“绝对链接值中的不稳定循环依赖性!”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆