代码之家  ›  专栏  ›  技术社区  ›  sernaferna

GWT样式不适用

  •  0
  • sernaferna  · 技术社区  · 15 年前

    我在创造一个 千兆瓦 使用 UiBinder公司 ,我遇到了一个奇怪的问题,样式没有应用到我的元素上——直到我刷新浏览器,然后在页面刷新前的那一瞬间,样式被短暂应用。换句话说:

    1. 打开页面;不使用我定义的任何样式。
    2. 命中刷新
    3. 页面重新加载,不再使用样式

    *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 回复  |  直到 15 年前
        1
  •  0
  •   Romain Hippeau    15 年前

    而不是 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.
    
        2
  •  0
  •   sernaferna    15 年前

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

    这可能是我将小部件添加到UI中的方式;我不记得我最初是如何添加它的(以前更改太多了),但我现在将它添加到 VerticalPanel add(Widget) 方法,并且样式现在可以毫无问题地应用。

    感谢那些跟在我后面的评论人。我希望我有一个更满意的答案。。。

    推荐文章