我想在GWT DateBox中设置一个水印/占位符。我知道如何在普通的TextBox中使用onFocus和onBlur来设置水印/占位符。我假设在DateBox中执行此操作会相对类似。设置文本目前看起来像这样,但根本不做任何事情。
Datebox box = new DateBox();
box.getTextBox().setText("mm/dd/yyyy");这是不是有不起作用的原因呢?
发布于 2011-12-15 06:23:19
我想你实际上在这里谈论的是能够设置占位符文本。我发布了一个针对TextBox elements here before的解决方案。该过程将非常相似:
public class DateField extends DateBox {
String placeholder = "";
/**
* Creates an empty DateField.
*/
public DateField() {}
/**
* Gets the current placeholder text for the date box.
*
* @return the current placeholder text
*/
public String getPlaceholder() {
return placeholder;
}
/**
* Sets the placeholder text displayed in the date box.
*
* @param placeholder the placeholder text
*/
public void setPlaceholder(String text) {
placeholder = (text != null ? text : "");
getElement().setPropertyString("placeholder", placeholder);
}
}然后用DateField对象替换您的DateBox对象,您只需调用someDateField.setPlaceholder("mm/dd/yyyy");即可。
发布于 2011-06-22 22:31:47
box.getTextBox().setValue("mm/dd/yyyy");https://stackoverflow.com/questions/6441070
复制相似问题