gpt4 book ai didi

java - 请给出一个简单的例子,如何使用 MigLayout 模拟 BorderLayout?

转载 作者:行者123 更新时间:2023-12-02 00:11:31 26 4
gpt4 key购买 nike

我希望布局的 WESTEAST 部分具有恒定的宽度。如何使用 MigLayout 进行设置?

更新

以下代码不会像边框布局那样调整大小:

package testing.Test_MigLayout_01;

import javax.swing.JButton;
import javax.swing.JRootPane;
import javax.swing.SwingUtilities;

import net.miginfocom.swing.MigLayout;

public class App201210042244
{

private class JFrame extends javax.swing.JFrame {

{
setLayout(new MigLayout());

add(new JButton("1"), "dock east, width 120");
add(new JButton("2"), "west");
add(new JButton("3"), "center");
add(new JButton("4"), "north");
add(new JButton("5"), "south");

}

}

public App201210042244() {
SwingUtilities.invokeLater(new Runnable() {

public void run() {
JFrame jFrame = new JFrame();
jFrame.pack();
jFrame.setVisible(true);

}
});
}


public static void main( String[] args )
{
new App201210042244();
}
}

窗口内部的大小保持不变:

enter image description here

最佳答案

panel.add(new JButton("1"), "dock east, width 120");
panel.add(new JButton("2"), "west");
panel.add(new JButton("3"), "center");
panel.add(new JButton("4"), "north");
panel.add(new JButton("5"), "south");

dock 关键字可以省略。

更新:

如果您希望在调整窗口大小时所有组件都展开:

panel.setLayout(new MigLayout("fill"));
panel.add(new JButton("1"), "dock east, width 120");
panel.add(new JButton("2"), "west");
panel.add(new JButton("3"), "center, grow");
panel.add(new JButton("4"), "north");
panel.add(new JButton("5"), "south");

关于java - 请给出一个简单的例子,如何使用 MigLayout 模拟 BorderLayout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12732355/

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