0

I have two components which I would like to both fill the same cell in a 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

(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?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
ulmangt
  • 5,343
  • 3
  • 23
  • 36

2 Answers2

4

I ended up solving the issue by giving the first component an id in MigLayout:

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):

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

ulmangt
  • 5,343
  • 3
  • 23
  • 36
  • lifesaver! I wonder thought if this is the best/recommended way to achieve this! There aren't a lot of examples out there! – BabaNew May 10 '18 at 20:00
0

Place them in a panel with CardLayout and swap when necessary.

StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • The components are transparent and I need both showing at once. I figured out how to do it though (see my answer). – ulmangt Apr 08 '12 at 06:04