gpt4 book ai didi

java - 如何使第一列增长,而所有其他列在 MigLayout 中具有最小尺寸?

转载 作者:行者123 更新时间:2023-12-02 06:27:45 26 4
gpt4 key购买 nike

代码:

public class Try_Grow_01 {

public static void main(String[] args) {

JFrame frame = new JFrame();

frame.setLayout(new MigLayout("fill, debug", "[fill]5[5]"));

frame.add(new JButton("one"), "");
frame.add(new JButton("two"), "");
frame.add(new JButton("three"), "");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

}

}

结果是

enter image description here

即右侧的两个细胞也生长,但我希望它们不要生长。

如何实现?

最佳答案

如果您希望第一个单元格增长并填充所有可用空间,则必须按如下方式创建 MigLayout:

frame.setLayout(new MigLayout("fill, debug", "[fill, grow][][]"));

enter image description here

如果您希望第一个单元格增长但不填充可用空间,则必须按如下方式创建 MigLayout:

frame.setLayout(new MigLayout("fill, debug", "[grow][][]"));

enter image description here

查看 Quick Start guide 的第 6 页

关于java - 如何使第一列增长,而所有其他列在 MigLayout 中具有最小尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20362115/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com