Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I wrap a very long line of text in a GWT label?

This is an extract of my code at the moment:

VerticalPanel mainPanel = new VerticalPanel();
RootPanel.get("messages").add(mainPanel);

HorizontalPanel tempPanel = new HorizontalPanel();
tempPanel.setSize("100px", "200px");

Label content = new Label("AAAveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongtextZZZ");
content.setWidth("50px");
content.setWordWrap(true);

tempPanel.add(content);
mainPanel.add(tempPanel);

The label displays but it does not wrap. If I insert a space it seems that word wrap works, but I guess I want character wrap. Any ideas?

I do not want a horizontal scrollbar.

like image 328
walter Avatar asked Feb 28 '23 03:02

walter


2 Answers

This is really more of a CSS question, than a GWT question. setWordWrap() is typically used to un-set word wrap on a div -- word wrapping (on whitespace) is the default.

What you want to do is add some CSS to the Label that says { word-wrap: break-word; }

More information here.

like image 129
Jason Hall Avatar answered Mar 08 '23 00:03

Jason Hall


I used label.setStyleAttribute("whiteSpace", "normal");

like image 21
Uncle Iroh Avatar answered Mar 08 '23 00:03

Uncle Iroh