ListBox gwt中修剪的单词之间的空格? [英] Whitespaces between words trimmed in ListBox gwt?

查看:81
本文介绍了ListBox gwt中修剪的单词之间的空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gwt项目中使用ListBox.ListBox填充多个记录,每个记录都有多个单词.记录之一在单词之间可能有多个空格.有没有办法保留这些空间.我尝试使用{white-space:pre;}向Listbox提供CSS,但无法正常工作.

I am using ListBox in a gwt project. ListBox populate multiple record and each record has multiple words. One of the record may have multiple spaces between words. Is there a way to preserve those spaces. I tried with providing css to Listbox with {white-space: pre;} but it is not working.

推荐答案

您必须将每个空格字符替换为不间断空格:& nbsp; .不幸的是, ListBox.addItem(String)会忽略那些& nbsp; 的.

You'll have to replace each space character by non-breaking spaces:  . Unfortunately, ListBox.addItem(String) will ignore those  's.

这是使用GWT Element API的一种解决方法:

Here's a workaround using GWT Element API:

    Element listElement = theListBox.getElement();

    OptionElement optionElement = Document.get().createOptionElement();
    optionElement.setInnerSafeHtml(SafeHtmlUtils.fromTrustedString("   you should see 3 spaces before this"));

    listElement.appendChild(optionElement);

这篇关于ListBox gwt中修剪的单词之间的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆