I've tried to center some components over several panels with the MigLayout (see the example here). It suddenly worked, when I split the page into percentages that are the same in all panels.
BUT I had to use the parameter "0:0" in front of each grow
and I dont understand what is happening exactly.
I went to the MigLayout CheatSheet-Page and the QuickStart-guide but only could find parameters with values > 0
The format is "min:preferred:max", however there are shorter versions since for instance it is seldom needed to specify the maximum size. A single value (E.g. "10") sets only the preferred size and is exactly the same as "null:10:null" and ":10:" and "n:10:n".
Two values (E.g. "10:20") means minimum and preferred size and is exactly the same as "10:20:null" and "10:20:" and "10:20:n"
But it does not explain what happens, when you use the 0 as a parameter, or why you need to use X:X or X:Y
at all and not for example X:Y:Z or X:X:X
?
So why do I need to use X:X
here to center my components?
The bit that matters here is the preferred size. In your other question, you said you used the following code to get it to work.
This would have also worked if you had wrote
Options you could use are (Where X <= Y <= Z)
So why does it do this?
It does this because the columns grow at the same rate and when you set the preferred size of the first column in all three panels you are setting the initial size as
MigLayout
sets the initial column size to the preferred size.In essensce you set columns to the same size and they grow at the same rate, so they remain equal sizes to each other. Hence they stay in line.
Working Example
Uses
:Y
whereY
is determined byFont Metrics