Tum
Tum

Reputation: 3652

How to make a very long non-stop string (without any space in it) break into many new lines when showing in HTMLPanel?

I have an HTMLPanel inside a FlowPanel which is inside a ScrollPanel like this.

<g:ScrollPanel> 
    <g:FlowPanel>
        <g:HTMLPanel ui:field="showMessageHTMLPanel" width="600px"/>
    </g:FlowPanel>
</g:ScrollPanel>

The showMessageHTMLPanel is used to hold the text that user enter a TextArea.

I want that the showMessageHTMLPanel should show exactly like how it was displayed in TextArea.

Ex,if user types in many sentences in new lines in TextArea, then the showMessageHTMLPanel should show similar like this:

This is text1

This is text2.

So here is what I did. I uses new SafeHtmlBuilder().appendEscapedLines(message).toSafeHtml().

HTML showMessageHTML = new HTML(new SafeHtmlBuilder().appendEscapedLines(message).toSafeHtml());
getView().getShowMessageHTMLPanel().add(showMessageHTML);

The result is that It breaks the lines quite OK, no problem.

However, When I type a non-stop very long string ( a String that doesn't have any space on it) into a TextArea. Ex, see this non-stop string:

"Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."

As you saw, even this non-stop string has no space, but when typing in TextArea then the string will automatically fall into new lines.

Ok, now when I show that non-stop string in getView().getShowMessageHTMLPanel(), it showed the text as one straight line without any line break:

Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.

The user has to scroll the scrollbar to see the complete text. This is unacceptable since it is too hard to see the whole line. Also many urls are non-stop string without spaces. So the user may not be able to copy the url.

How to make a very long non-stop string (without any space in it) break into many new lines when showing in HTMLPanel?

Or

Do you know any other widget that can handle this?

Upvotes: 0

Views: 112

Answers (1)

user2454340
user2454340

Reputation: 1220

I am sure, a simple css property should help.

word-wrap:break-word;  

Detail here

Upvotes: 1

Related Questions