如何将掩码放在TextInputCell中?

时间:2014-03-20 17:41:37

标签: java gwt gwt-bootstrap

我在列中有一个TextInputCell,如下所示:

TextInputCell textCell = new TextInputCell();
    Column<EffortCost, String> hourColumn = new Column<EffortCost, String>(textCell) {  
        public String getValue(EffortCost object) {
            String formatted = NumberFormat.getFormat("0.00").format(object.getHours());

            return formatted;
        }
    };

我的字符串返回:“1.00”如果我写了“1”。我想要相同的结果,但我不想形成字符串,我希望我的小部件在我把文本放在TextInputCell中的时候这样做,换句话说,我想在我写文本时自动格式化字符串TextInputCell。这就像“MaskedTextInputCell”。我怎样才能做到这一点?我可以看一些例子吗?

感谢您的关注。

1 个答案:

答案 0 :(得分:2)

您可以为hourColumn添加FieldUpdater。 它具有update()方法,该方法在此列中的单元格值更改时触发。例如:

hourColumn.setFieldUpdater(new FieldUpdater<EffortCost, String>() {
@Override
public void update(int index, EffortCost object, String value) {
    // do something when value changes
    // return NumberFormat.getFormat("0.00").format(object.getHours());
}
});

每次输入数字时,都会格式化并更新。