这个问题很简单,但看起来很复杂;我在网上搜索并尝试了很多,但没有找到适合我的解决方案! 我所需要的只是图标和文本之间没有空格:
这是代码:
Label subTitle = new Label("nel cammin di nostra vita mi trovai in selva oscura");
Label stpIMG = null;
stpIMG = new Label();
stpIMG.setContentMode(ContentMode.HTML);
stpIMG.setValue("<img src=\"VAADIN/themes/valo/images/sprite_svg_all.svg#ristampa\">");
stpIMG.setWidth("30px");
stpIMG.setHeight("20px");
HorizontalLayout subTitleLayout=null;
subTitleLayout = new HorizontalLayout(stpIMG,subTitle);
subTitleLayout.setExpandRatio(stpIMG, 1);
subTitleLayout.setExpandRatio(subTitle, 2);
subTitleLayout.setWidth("650px");
subTitleLayout.setSpacing(false);
mainLayout.addComponents(subTitleLayout);
我错了什么? 非常感谢
问题是
subTitleLayout.setExpandRatio(stpIMG, 1);
setExpandRatio
告诉布局展开包含 stpIMG
的槽。
我是这样解决这个问题的:
公共静态 HorizontalLayout BuildIconStampa(字符串...文本){
Label warnIMG = new Label();
warnIMG.setContentMode(ContentMode.HTML);
warnIMG.setValue("<img src=\"VAADIN/themes/valo/images/sprite_all2.svg#ristampa\">");
warnIMG.setWidth("30px");
warnIMG.setHeight("30px");
Label[] labels = new Label[text.length];
for (int i = 0; i < text.length; i++) {
Label body = new Label(text[i]);
body.setSizeFull();
body.setStyleName("bsr-gray");
labels[i] = body;
}
VerticalLayout vl = new VerticalLayout(labels);
HorizontalLayout result = new HorizontalLayout(warnIMG, vl);
result.setSpacing(true);
result.setExpandRatio(vl, 1);
return result;
}