简体   繁体   English

使用 MigLayout 用两个组件填充整个单元格

[英]Fill Entire Cell With Two Components Using MigLayout

I have two components which I would like to both fill the same cell in a MigLayout :我有两个组件,我希望它们都填充MigLayout中的同一个单元格:

For example, I want to give both components constraints something like this:例如,我想给两个组件约束是这样的:

cell 0 0 1 1, push, grow

and have them both be placed exactly over top of one another inside cell 0 0并将它们都放置在cell 0 0中的彼此之上

(If I just use the code above, they end up sharing space side-by-side in the cell) (如果我只使用上面的代码,它们最终会在单元格中并排共享空间)

What do I have to add to the MigLayout constraints to make this happen?我必须向MigLayout约束添加什么才能实现这一点?

I ended up solving the issue by giving the first component an id in MigLayout:我最终通过在 MigLayout 中给第一个组件一个id来解决这个问题:

cell 0 0 1 1, push, grow, id myid

Then explicitly positioned the second component on top of the first using the first component's bounds (referenced using the id):然后使用第一个组件的边界(使用 id 引用)将第二个组件显式定位在第一个组件之上:

pos myid.x myid.y myid.x2 myid.y2

Place them in a panel with CardLayout and swap when necessary.将它们放在带有 CardLayout 的面板中,并在必要时交换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM