简体   繁体   中英

how to space between components

the issue is very easy, but seems quite complicate;I've search on inte.net and try a lot but there is not way to find a solution for me:! All I need is not having space between an icon and a text: 在此处输入图像描述

this is the code:

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);

And is not easy to accomplish even if is so easy; What I'm wrong? thanks so much

The problem is subTitleLayout.setExpandRatio(stpIMG, 1);

setExpandRatio is telling the layout to expand the slot containing stpIMG .

I've solved the issue in this way:

public static HorizontalLayout BuildIconStampa(String... text) {

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;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM