GWT - 如何在 TextItem 中只允许数字?

GWT - How to allow only numbers in TextItem?

我有以下 TextItem

final TextItem txtFromAmt = new TextItem();
txtFromAmt.setWrapTitle(false);
txtFromAmt.setShowTitle(false);
txtFromAmt.setAlign(Alignment.LEFT);
txtFromAmt.setWidth(100);

我希望这个 TextItem 只允许数字。我怎样才能做到这一点? TextItem 中有 property/method 可以做到这一点吗?

你试过了吗:

    txtFromAmt.setKeyPressFilter("[0-9]");

希望对您有所帮助。

请检查以下文档。

https://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/widgets/form/fields/TextItem.html#setKeyPressFilter-java.lang.String-

按照 El Hoss 的建议尝试相同的方法

txtFromAmt.setKeyPressFilter("[0-9.]"); // allows only digits and .(dot)