GWT日期框水印/占位符
我想在GWT日期框内设置水印/占位符。我知道如何使用onFocus和onBlur在普通文本框中设置水印/占位符。我假设在日期框中这样做会相对类似。设置文本当前看起来像这样,但根本不起任何作用GWT日期框水印/占位符,gwt,watermark,datebox,Gwt,Watermark,Datebox,我想在GWT日期框内设置水印/占位符。我知道如何使用onFocus和onBlur在普通文本框中设置水印/占位符。我假设在日期框中这样做会相对类似。设置文本当前看起来像这样,但根本不起任何作用 Datebox box = new DateBox(); box.getTextBox().setText("mm/dd/yyyy"); 有没有什么原因使它不起作用?我想你在这里真正谈论的是能够设置占位符文本。我发布了一个TextBox元素的解决方案。过程将非常相似: box.getTex
Datebox box = new DateBox();
box.getTextBox().setText("mm/dd/yyyy");
有没有什么原因使它不起作用?我想你在这里真正谈论的是能够设置占位符文本。我发布了一个
TextBox
元素的解决方案。过程将非常相似:
box.getTextBox().setValue("mm/dd/yyyy");
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”)代码>我想您在这里实际谈论的是能够设置占位符文本。我发布了一个TextBox
元素的解决方案。过程将非常相似:
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”)代码>即使尝试此操作,日期框也不会显示任何文本。好奇的是,文本框中的setText和setValue有什么区别(很抱歉没有问题)?我刚刚试过,它很有效,你是不是在某个时候写得太多了?@chrissetText
继承自HasText
,实际上只是将值传递给setValue
。即使尝试了这一点,日期框也不会显示任何文本。好奇的是,文本框中的setText和setValue有什么区别(很抱歉这个问题)?我刚刚试过,它很有效,你是不是在某个时候写得太多了?@chrissetText
继承自HasText
,实际上只是将值传递给setValue
。