miglayout关于列的问题

发布于 2024-09-30 11:29:27 字数 975 浏览 7 评论 0原文

我在列中有一些控件,我希望它们看起来像这样,但有一行是例外:

+----+------------------+----+--------------------+
| X1 | Y1               | X5 | Y5                 |
+----+------------------+----+--------------------+
| X2 | Y2               | X6 | Y6                 |
+----+------------------+----+--------------------+
| X3 | Y3               | X7 | Y7                 |
+----+-----+------------+----+--------------------+
| Special1 |  Special 2 with long description     |
+----+-----+------------+----+--------------------+
| X4 | Y4               | X8 | Y8                 |
+----+------------------+----+--------------------+

我想知道如何使用 MigLayout 来做到这一点。我正在使用 Swing JavaBuilders 及其压缩的 YAML 语法:

X1        Y1               X5    Y5
X2        Y2               X6    Y6
X3        Y3               X7    Y7
Special1     Special2
X4        Y4               X8    Y8

我基本上想做的是使一行(Special1/Special2)成为例外,但我不确定如何做到这一点(上面的 YAML 片段不正确) 。

I have some controls in columns that I would like to look like this, and there is one row that is an exception:

+----+------------------+----+--------------------+
| X1 | Y1               | X5 | Y5                 |
+----+------------------+----+--------------------+
| X2 | Y2               | X6 | Y6                 |
+----+------------------+----+--------------------+
| X3 | Y3               | X7 | Y7                 |
+----+-----+------------+----+--------------------+
| Special1 |  Special 2 with long description     |
+----+-----+------------+----+--------------------+
| X4 | Y4               | X8 | Y8                 |
+----+------------------+----+--------------------+

and I was wondering how to do it with MigLayout. I am using Swing JavaBuilders with its condensed YAML syntax:

X1        Y1               X5    Y5
X2        Y2               X6    Y6
X3        Y3               X7    Y7
Special1     Special2
X4        Y4               X8    Y8

What I basically would like to do is make one row (the Special1/Special2) an exception, but I'm not sure how to do it (the above YAML fragment is not right).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月流歌 2024-10-07 11:29:27

这应该可以做到:

public static void main(String[] args)
{
    JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(400, 250));

    Container cp = frame.getContentPane();
    cp.setLayout(new MigLayout("fill, debug"));

    String wrap = "wrap,";
    String span2 = "spanx 2,";
    String span3 = "spanx 3,";

    cp.add(new JLabel("X1"));
    cp.add(new JLabel("Y1"), span2);
    cp.add(new JLabel("X5"));
    cp.add(new JLabel("Y5"), wrap);
    cp.add(new JLabel("X2"));
    cp.add(new JLabel("Y2"), span2);
    cp.add(new JLabel("X6"));
    cp.add(new JLabel("Y6"), wrap);
    cp.add(new JLabel("X3"));
    cp.add(new JLabel("Y3"), span2);
    cp.add(new JLabel("X7"));
    cp.add(new JLabel("Y7"), wrap);
    cp.add(new JLabel("Special 1"), span2);
    cp.add(new JLabel("Special 2 with long description"), span3 + wrap);
    cp.add(new JLabel("X4"));
    cp.add(new JLabel("Y4"), span2);
    cp.add(new JLabel("X7"));
    cp.add(new JLabel("Y8"));

    frame.pack();
    frame.setVisible(true);
}

享受。

this should do it:

public static void main(String[] args)
{
    JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(400, 250));

    Container cp = frame.getContentPane();
    cp.setLayout(new MigLayout("fill, debug"));

    String wrap = "wrap,";
    String span2 = "spanx 2,";
    String span3 = "spanx 3,";

    cp.add(new JLabel("X1"));
    cp.add(new JLabel("Y1"), span2);
    cp.add(new JLabel("X5"));
    cp.add(new JLabel("Y5"), wrap);
    cp.add(new JLabel("X2"));
    cp.add(new JLabel("Y2"), span2);
    cp.add(new JLabel("X6"));
    cp.add(new JLabel("Y6"), wrap);
    cp.add(new JLabel("X3"));
    cp.add(new JLabel("Y3"), span2);
    cp.add(new JLabel("X7"));
    cp.add(new JLabel("Y7"), wrap);
    cp.add(new JLabel("Special 1"), span2);
    cp.add(new JLabel("Special 2 with long description"), span3 + wrap);
    cp.add(new JLabel("X4"));
    cp.add(new JLabel("Y4"), span2);
    cp.add(new JLabel("X7"));
    cp.add(new JLabel("Y8"));

    frame.pack();
    frame.setVisible(true);
}

enjoy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文