[英]How to middle align through MigLayout
I am creating a desktop application using swing and miglayout. 我正在使用swing和miglayout创建一个桌面应用程序。 How would I get the below gui? 我将如何获得以下gui? C1 being component 1. C1是组件1。
+-----+ +-----+
| C1 | | C2 |
+-----+ +-----+ +----+
+-----+ +-----+ | C4 |
| C3 | | C4 | +----+
+-----+ +-----+
Thank you. 谢谢。
Update with regards to the below answer. 关于以下答案的更新。
Code is: 代码是:
panel = new JPanel(); panel = new JPanel();
MigLayout layout = new MigLayout("debug", "[][][]");
panel.setLayout(layout);
JCheckBox reptJCheckBox = new JCheckBox("REPT");
JCheckBox tstcJCheckBox = new JCheckBox("TSTC");
JCheckBox devJCheckBox = new JCheckBox("DEV");
JCheckBox tstyCheckBox = new JCheckBox("TSTY");
JButton openButton = new JButton("Open");
panel.add(reptJCheckBox);
panel.add(tstcJCheckBox, "wrap");
panel.add(tstyCheckBox);
panel.add(devJCheckBox);
panel.add(openButton, "spany 2, wrap");
Note that you can't add the same component twice in a container, so having C1 and C2 tiwce is a mistake. 请注意,您不能在一个容器中两次添加相同的组件,因此错开C1和C2是错误的。
About components layout, I think the question is how to vertically center C3 component. 关于组件布局,我认为问题是如何使C3组件垂直居中。 Well this is the default behavior when you span rows using spany
constraint: component gets vertically centered. 好吧,这是使用spany
约束跨行时的默认行为:组件垂直居中。 Just try this snippet: 只需尝试以下代码段:
MigLayout layout = new MigLayout("debug, fill", "[][][]");
JPanel panel = new JPanel(layout);
panel.add(new JButton("Button"));
panel.add(new JButton("Button"));
panel.add(new JButton("Button"), "spany 2, wrap");
panel.add(new JButton("Button"));
panel.add(new JButton("Button"));
See MigLayout Quick Start Guide for further details about constraints. 有关约束的更多详细信息,请参见《 MigLayout快速入门指南》 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.