Java 设置CSS样式Uibinder Gwt
我想在onBlur事件中使用java代码更改g:label的颜色。 我正在使用eclipse,UIBinder 这就是我的想法,虽然它不起作用 在我的StandardDocumentDownload.ui.xml文件中Java 设置CSS样式Uibinder Gwt,java,xml,gwt,uibinder,Java,Xml,Gwt,Uibinder,我想在onBlur事件中使用java代码更改g:label的颜色。 我正在使用eclipse,UIBinder 这就是我的想法,虽然它不起作用 在我的StandardDocumentDownload.ui.xml文件中 <ui:style> .testStyle { } .styleRequiredData { color:red; } </ui:style> 如何在触发事件时将红色添加到标签的现有样式中 请
<ui:style>
.testStyle {
}
.styleRequiredData
{
color:red;
}
</ui:style>
如何在触发事件时将红色添加到标签的现有样式中
请参见“内联样式的编程访问”下的
对你来说,应该是这样的:
<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("");
}
}
}
.测试风格{
}
.styledData
{
颜色:红色;
}
公共类YourClass扩展小部件{
接口MyStyle扩展了CssResource{
字符串testStyle();
字符串styleRequiredData();
}
@尤菲尔德风格;
/* ... */
@UiHandler(“comboTitle”)
无效onComboTitleBlur(模糊事件){
int title=comboTitle.getSelectedIndex();
如果(标题==0){
labTitleReq.setText(“请输入值”);
labTitle.getElement().addClassName(style.styleRequiredData);
}否则{
标签标题如setText所示(“”);
}
}
}
请参见“对内联样式的编程访问”
对你来说,应该是这样的:
<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("");
}
}
}
.测试风格{
}
.styledData
{
颜色:红色;
}
公共类YourClass扩展小部件{
接口MyStyle扩展了CssResource{
字符串testStyle();
字符串styleRequiredData();
}
@尤菲尔德风格;
/* ... */
@UiHandler(“comboTitle”)
无效onComboTitleBlur(模糊事件){
int title=comboTitle.getSelectedIndex();
如果(标题==0){
labTitleReq.setText(“请输入值”);
labTitle.getElement().addClassName(style.styleRequiredData);
}否则{
标签标题如setText所示(“”);
}
}
}
我花了一段时间才找到它,但是没有找到文档;”“告诉你怎么做。下面是代码片段
UiBinder:
说明:
元素有一个新属性,
type='com.my.app.MyFoo.MyStyle'。这意味着它需要实施
该接口(在上面MyFoo小部件的Java源代码中定义)
并提供它调用的两个CSS类,enabled和disabled
现在看看@UiField MyStyle样式;MyFoo.java中的字段。那个
允许代码访问为生成的CssResource
块setEnabled方法使用该字段应用已启用和
在小部件打开和关闭时禁用样式
您可以在样式中自由定义任意数量的其他类
具有指定类型的块,但您的代码只能访问
接口所需的
我花了一段时间才找到它,但是文件;”“告诉你怎么做。下面是代码片段 UiBinder: 说明: 元素有一个新属性, type='com.my.app.MyFoo.MyStyle'。这意味着它需要实施 该接口(在上面MyFoo小部件的Java源代码中定义) 并提供它调用的两个CSS类,enabled和disabled 现在看看@UiField MyStyle样式;MyFoo.java中的字段。那个 允许代码访问为生成的CssResource 块setEnabled方法使用该字段应用已启用和 在小部件打开和关闭时禁用样式 您可以在样式中自由定义任意数量的其他类 具有指定类型的块,但您的代码只能访问 接口所需的
我推荐
labTitle.addStyleName(style.styleRequiredData())如果可能的话,最好不要使用javascript元素如果可能,最好不要使用javascript元素。
<ui:style type='com.my.app.MyFoo.MyStyle'>
.redBox { background-color:pink; border: 1px solid red; }
.enabled { color:black; }
.disabled { color:gray; }
</ui:style>
<div class='{style.redBox} {style.enabled}'>I'm a red box widget.</div>
</ui:UiBinder>
public class MyFoo extends Widget {
interface MyStyle extends CssResource {
String enabled();
String disabled();
}
@UiField MyStyle style;
/* ... */
void setEnabled(boolean enabled) {
getElement().addClassName(enabled ? style.enabled() : style.disabled());
getElement().removeClassName(enabled ? style.disabled() : style.enabled());
}
}