How to wrap a label text which is added inside a grid column?

I am writing a following code in gwt

 Grid  grid=new Grid(1,2);
 Label label=new Label("LongTextInLabel");
 Label label1=new Label("LongTextInLabel1");
 grid.setWidget(0, 0, label));
 grid.setWidget(0, 1, label1);
 grid.setWidth("100%");
 label.setwidth("50%");
 label1.setwidth("50%");

I want to wrap a text in label if it is overflowing a label width. I tried assigning

label.setWordWrap(true);

but somehow it is not working. Also i tried assigning it through css . Any workaround for this?

Thanks

Answer

I would do that with css, just set a class to the label you want to wrap the text and use the white-space and text-overflow properties

grid.addStyleName("fixed")
label.addStyleName("wrap")

.fixed {
    table-layout: fixed;
}

.wrap {
     white-space: nowrap; 
     text-overflow: ellipsis;
     overflow: hidden;
}

Leave a Reply

Your email address will not be published. Required fields are marked *