GWT样式不适用

时间:2010-04-21 14:35:50

标签: gwt uibinder

我正在创建一个使用 UiBinder GWT 应用程序,我遇到了一个奇怪的问题,其中样式不适用于我的元素 - 直到我刷新浏览器,然后简短地应用样式,在页面刷新之前的一小段时间内。换句话说:

  1. 打开页面;没有使用我定义的样式。
  2. 点击刷新
  3. 在页面空白之前,使用样式的时间只有几分之一
  4. 页面重新加载,没有样式
  5. 我要包含我的整个*ui.xml文件,因为它不是太大。

    <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
    <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
        xmlns:g="urn:import:com.google.gwt.user.client.ui">
        <ui:style>
            .idLabelStyle {
                font-weight: bold;
                text-align: center;
                width: 100px;
                border-style: solid;
                border-width: 1px;
                margin-right: 5px;
            }
    
            .nameLabelStyle {
                font-weight: bold;
                text-align: center;
                width: 500px;
                border-style: solid;
                border-width: 1px;
                margin-right: 5px;
            }
    
            .addressLabelStyle {
                font-weight: bold;
                text-align: center;
                width: 500px;
                border-style: solid;
                border-width: 1px;
            }
        </ui:style>
        <g:HTMLPanel>
            <g:HorizontalPanel>
                <g:Label addStyleNames="{style.idLabelStyle}">ID</g:Label>
                <g:Label addStyleNames="{style.nameLabelStyle}">Name</g:Label>
                <g:Label addStyleNames="{style.addressLabelStyle}">Address</g:Label>
            </g:HorizontalPanel>
        </g:HTMLPanel>
    </ui:UiBinder> 
    

    我真的希望我错过了一些简单的事情。

3 个答案:

答案 0 :(得分:0)

而不是addStyleNames=使用setStyleName=setStylePrimaryName=我过去曾遇到过这个问题,并且在我的案例中修复了这个问题。 注意:两种可能性如下所示......

setStyleName
Clears all of the object's style names and sets it to the given style. You should normally use setStylePrimaryName(String) unless you wish to explicitly remove all existing styles.

setStylePrimaryName
Sets the object's primary style name and updates all dependent style names.

答案 1 :(得分:0)

幸运或遗憾的是,我不再在我的应用中使用此小部件了;但是,我不想丢失代码,因为这个问题让我疯了,我想知道我错过了什么。

不幸的是,在更改我的代码,然后重新添加小部件来测试它之后,我再也无法重现这个问题了。

这可能是我将小部件添加到我的UI的方式;我不记得我最初是如何添加的(之前有太多变化),但我现在使用VerticalPanel方法将其添加到add(Widget),现在样式正在应用没问题。

感谢评论员在我的狂追追逐中跟随我。我希望我有一个更令人满意的答案......

答案 2 :(得分:0)

在UiBinder中使用基于Cell的面板时;在标签中包装子元素并单独设置其对齐和大小。

http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/ui/CellPanel.html