[英]How to set GWT cell background color
i would like to change the background-color property of a gwt cell column. 我想改变gwt细胞列的背景颜色属性。 The problem is that this color can change at each render of the cell (background color depends on the value of the cell).
问题是这种颜色可能会在每次渲染细胞时发生变化(背景颜色取决于细胞的值)。
I have already tried to override the cell style names method of TextColumn as follow : 我已经尝试覆盖TextColumn的单元格样式名称方法,如下所示:
@Override
public String getCellStyleNames(final Context context, final Object data) {
if (my_condition) return "a custom style";
else return "default style"; // or null...
}
Well as you certainly know its only add a class name to the property so i can't use it to set a color "dynamically" due to the static css file definition. 好吧,你当然知道它只为属性添加一个类名,所以由于静态css文件定义,我不能用它来“动态”设置颜色。
Thx for ur help ! 谢谢你的帮助!
For dynamic update of 'color' property I would recommend to extend TextCell (and pass it to 'TextColumn' constructor). 对于'color'属性的动态更新,我建议扩展TextCell(并将其传递给'TextColumn'构造函数)。 Something like that:
像这样的东西:
public class CustomCell extends TextCell<String> {
interface Template extends SafeHtmlTemplates {
@Template("<div style=\"color:{0}\">{1}</div>")
SafeHtml div(String url, String text);
}
private static Template template;
public CustomCell () {
if (template == null) {
template = GWT.create(Template.class);
}
}
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
String color = "red";
if (value != null) {
// The template will sanitize the URI.
sb.append(template.div(color, value));
}
}
}
public class CustomColumn<T> extends TextColumn<T> {
public CustomColumn() {
super(new CustomCell());
}
}
Since you didn't give details of the component you are using, I'll give a generic suggestion for trying to find out which properties you might need to play with. 由于您没有提供您正在使用的组件的详细信息,因此我将提供一个通用建议,以尝试找出您可能需要使用的属性。
I use eclipse and suggest using the GWT Designer to help you with POC stuff. 我使用eclipse并建议使用GWT Designer来帮助你处理POC。 It helps me get an idea of which properties I might want to play with:
它可以帮助我了解我可能想要使用哪些属性:
GWT Designer Refererence: https://developers.google.com/web-toolkit/tools/download-gwtdesigner GWT Designer Refererence: https : //developers.google.com/web-toolkit/tools/download-gwtdesigner
Example of how to use GWT Designer: 如何使用GWT Designer的示例:
https://developers.google.com/web-toolkit/tools/gwtdesigner/tutorials/loginmanager https://developers.google.com/web-toolkit/tools/gwtdesigner/tutorials/loginmanager
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.