如何在 GWT 标签中换行很长的文本行?
这是我目前代码的摘录:
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);
标签显示但不换行。 如果我插入一个空格,似乎可以自动换行,但我想我想要字符换行。 有什么想法吗?
我不想要水平滚动条。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这实际上更像是一个 CSS 问题,而不是一个 GWT 问题。
setWordWrap()
通常用于取消在 div 上设置自动换行 - 默认情况下自动换行(在空白处)。你想要做的就是在标签中添加一些CSS,上面写着
{ word-wrap: break-word; }
更多信息此处。
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.
我使用了 label.setStyleAttribute("whiteSpace", "normal");
I used
label.setStyleAttribute("whiteSpace", "normal");