How to prevent a Label's width from collapsing to 0

According to the documentation if you have an empty Label (a Label with an empty string) the width will collapse to 0. However the documentation also says: “If you want a gap that has adjustable width or height, you can use an empty label if you specify a height or width for it” The problem is that when I do this the width still collapses to 0. I need the width to keep it’s size because I use a different color for the background.


setting the height and width of the Label by methods setHeight()/setWidth() should work regardless of the content of the Label.

Something that could be happening is that if the width/height of the parent component has not been set explicitly (see, using relative units (e.g. percentage) does not work, and that’s why the Label is not showing correctly.
E.g. when the Label is added to a VerticalLayout (which doesn’t have a defined height), the height of Label cannot be set as percentage value etc., or when added to HorizontalLayout, the width cannot be a percentage value etc., as they’re evauluated basically to zero.

If that doesn’t resolve the issue, could you give an example snippet where it doesn’t work?

BR, Katri