问题
According to the documentation if you have an empty Label (a Label with an empty string) the width will collapse to 0. That being said 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" However 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.
回答1:
For me adding style to whatEverIsTheStyleName.scss
that specifies width works fine:
.emptyLabel {
width: 500px;
}
Then simply:
emptyLabel.addStyleName("emptyLabel");
Setting it in a code like emptyLabel.setWidth(500, Unit.PIXELS);
seems not to work.
来源:https://stackoverflow.com/questions/46870163/how-to-set-width-for-vaadin-label-with-empty-string