GWT DataGrid 更改行字体大小

GWT DataGrid change row font-size

我创建了一个 DataGrid。现在我希望用户能够单击带有 + 和 - 符号的按钮,以使数据网格中的文本变大或变小。

我知道我可以做类似的事情:

DataGrid table = new DataGrid<Row>();
table.setRowStyles(new RowStyles<LogRow>() {
    @Override
    public String getStyleNames(LogRow row, int rowIndex) {
      return className;
    }
});

但是我想动态改变字体。我的意思是 "current font size + 1" 或 "current font size - 1".

有办法吗?还是我必须为每个字体大小创建特殊的 class?

我尝试在 GSS 中定义一个常量,它从我的 class 的 "getFontSize()" 方法中获取它的值,但它是一个常量,所以它只会获取该值一次,然后忽略我的 class.

中字体大小 属性 的任何更改

我试过了

table.getElement().getStyle().setFontSize(newFontSize, Style.Unit.PX);

table.getRowContainer().getStyle().setFontSize(newFontSize, Style.Unit.PX);

但没有成功。也许我必须定位子元素?

感谢您的帮助。

在您的样式表中使用 @eval。也许这段代码可以帮助你

//refer to a method, that returns a string for your front size.
//your can change the return value of getFontSize() at any time
@eval FONT_SIZE com.your.app.client.css.getFontSize();
@external .fontSize;
.fontSize{
    font-size: FONT_SIZE;
}

然后注入你的样式,当你想改变字体大小时替换它:

public class Css {
    public static String FONT_SIZE= "18px";

    public static String getFontSize() {
         return FONT_SIZE;
    }

    public Css(){
        CssResource res = GWT.create(YourRes.class);
        StyleElement styleElement = StyleInjector.injectStylesheet(res.getText());
        FONT_SIZE = "25px";
        StyleInjector.setContents(styleElement , res.getText());
    }
}