我想使用 MiG Layout 实现本示例中的布局。所以最后一个 JButton 位于 JFrame 的底部。
public class MainFrame extends JFrame {
public static void main(String[] args) {
MainFrame mainFrame = new MainFrame();
mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
mainFrame.setPreferredSize(new Dimension(400, 300));
mainFrame.pack();
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
}
public MainFrame() {
this.setLayout(new MigLayout("debug", "[grow, fill]", "[][][]push[]"));
this.add(new JButton("Test1"), "wrap");
this.add(new JButton("Test2"), "wrap");
this.add(new JButton("Test..."), "wrap");
this.add(new JButton("TestBottom"), "");
}
}
我的问题是我要添加的 JButton 的数量是可变的,所以我不能使用 MiG 布局中的行定义,所以我尝试了这段代码(和几个派生)
public MainFrame() {
this.setLayout(new MigLayout("debug", "[grow, fill]", ""));
this.add(new JButton("Test1"), "wrap");
this.add(new JButton("Test2"), "wrap");
this.add(new JButton("Test..."), "wrap");
this.add(new JButton("TestBottom"), "gaptop push");
}
但不幸的是,这不能按预期工作。
有什么建议么?提前致谢。