我最初在 miglayout 论坛上发布了这个问题,经过 534 次浏览但没有答案,我决定在那里尝试一下;-)
我试图从 MigLayout 白皮书中扩展“初始示例”,以便添加一个始终位于对话框底部的“确定”按钮。
不幸的是,我发现的唯一解决方案是添加一个会增长的“假面板”:
public class TestResize extends JDialog {
protected JPanel contentPane;
public TestResize() {
super((Dialog) null, "Test resize", true);
setupUI();
setContentPane(contentPane);
}
private void setupUI() {
contentPane = new JPanel(new MigLayout());
contentPane.add(new JLabel("Enter size:"), "");
contentPane.add(new JTextField(""), "grow, pushx, wrap");
contentPane.add(new JLabel("Enter weight:"), "");
contentPane.add(new JTextField(""), "grow, pushx, wrap");
// fake panel that is allowed to grow
contentPane.add(new JPanel(), "span 2, grow, pushy, wrap");
JButton okButton = new JButton("Ok");
JPanel buttonPanel = new JPanel(new MigLayout("", "[center, grow]"));
buttonPanel.add(okButton, "");
contentPane.add(buttonPanel, "dock south");
}
public static void main(String[] args) {
TestResize dialog = new TestResize();
dialog.pack();
dialog.setVisible(true);
}
}
我真的一点也不喜欢这种方法……但是有更好的方法吗?
(貌似我不能上传图片,但我想得到的用户界面在我的原始帖子中是可见的)
谢谢!