Reputation: 8210
I don't have a lot of miglayout experience, so please advise. I have a layout where the first column is a JCheckBox
that spans 2 rows. The second column has 2 JLabels, 1 in each row.
It seemed the default layout is for the checkbox to be vertically aligned in the center of the 2 rows. I want it to be aligned with the text in the top JLabel
, so I used aligny top
on the JCheckBox
.
rightSubPanel.add(stepCheck,"span 1 2, aligny top");
rightSubPanel.add(stepTitle);
rightSubPanel.add(subTitle, "gapleft 40");
However the JCheckbox
is still slightly lower than the text in the adjacent JLabel
.
See the attached picture:
Can anyone explain this or suggest a better way to do this?
update Using debug the layout looks like below. The solution is to add a 5 pixel gap above each of the stepTitles such as:
rightSubPanel.add(stepTitle,"gaptop 5");
Upvotes: 1
Views: 345
Reputation: 1587
add the debug
tag in the constructor of MigLayout. This will show borders around each element. I assume that stepCheck
in your example is the checkbox plus "STEP 1:". aligny top
will align the topmost end of the element. I guess the checkbox has some additional border around it, so that the visible part of it is not at the very top. you can add an empty border around the stepTitle
element to achieve the same.
Upvotes: 1