gpt4 book ai didi

Java MigLayout 拉伸(stretch)为 BorderLayout

转载 作者:行者123 更新时间:2023-12-02 08:03:26 24 4
gpt4 key购买 nike

请问,MigLayout 中是否有任何选项可以将某些元素拉伸(stretch)到 JPanel 大小的 100%?就像使用 BorderLayout 将 JButton 添加到 JFrame 中一样?谢谢。

代码:

Jframe frame = new JFrame();  
frame.setLayout(new MigLayout());
JPanel mainPanel = new JPanel(new MigLayout());
mainPanel.add(new JButon());

我希望 JButton 填充 JFrame 的整个区域。 JButton只是我用来解释我想要实现的目标的引用对象。

最佳答案

您可以为此使用“增长”。这应该与在中心添加边框布局相同。

请参阅下面的 miglayout 备忘单

http://migcalendar.com/miglayout/cheatsheet.html

public class test {

public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel mainPanel = new JPanel(new MigLayout());
mainPanel.add(new JButton(), "dock center");
// or
//mainPanel.add(new JButton(), "dock center");

frame.getContentPane().add(mainPanel);
frame.setSize(200,200);
frame.setVisible(true);
}
}

关于Java MigLayout 拉伸(stretch)为 BorderLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8547755/

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