设置CSS样式Uibinder Gwt

Ari*_*ule 1 java xml gwt uibinder

我想在onBlur事件上使用java代码更改ag:label的颜色.我正在使用eclipse,UIBinder.

这是我的想法,虽然它不起作用.

在我的StandardDocumentDownload.ui.xml文件中

<ui:style>     
   .testStyle {
   }
   .styleRequiredData
   {
        color:red;

    }
 </ui:style>
Run Code Online (Sandbox Code Playgroud)

这是我的standardDocumentDownload.java文件中的事件

@UiHandler("comboTitle")
void onComboTitleBlur(BlurEvent event) {
    int title = comboTitle.getSelectedIndex();

    if(title == 0)
    {
        labTitleReq.setText("Please enter a value");
        labTitle.addStyleName("styleRequiredData");
    }
    else
    {
        labTitleReq.setText("");
    }

}
Run Code Online (Sandbox Code Playgroud)

如何在事件发生时将红色添加到标签的现有样式中.

亲切的问候

jon*_*asr 12

请参阅此处对内联样式的编程访问

对你来说,它应该是这样的:

<ui:style type="com.yourapp.YourClass.MyStyle">     
    .testStyle {
    }
    .styleRequiredData
    {
        color:red;
    }
</ui:style>

public class YourClass extends Widget {
    interface MyStyle extends CssResource {
        String testStyle();
        String styleRequiredData();
    }

    @UiField MyStyle style;

    /* ... */

    @UiHandler("comboTitle")
    void onComboTitleBlur(BlurEvent event) {
        int title = comboTitle.getSelectedIndex();
        if(title == 0){
            labTitleReq.setText("Please enter a value");
            labTitle.getElement().addClassName(style.styleRequiredData);
        } else {
            labTitleReq.setText("");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)