Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GWT日期框水印/占位符_Gwt_Watermark_Datebox - Fatal编程技术网

GWT日期框水印/占位符

GWT日期框水印/占位符,gwt,watermark,datebox,Gwt,Watermark,Datebox,我想在GWT日期框内设置水印/占位符。我知道如何使用onFocus和onBlur在普通文本框中设置水印/占位符。我假设在日期框中这样做会相对类似。设置文本当前看起来像这样,但根本不起任何作用 Datebox box = new DateBox(); box.getTextBox().setText("mm/dd/yyyy"); 有没有什么原因使它不起作用?我想你在这里真正谈论的是能够设置占位符文本。我发布了一个TextBox元素的解决方案。过程将非常相似: box.getTex

我想在GWT日期框内设置水印/占位符。我知道如何使用onFocus和onBlur在普通文本框中设置水印/占位符。我假设在日期框中这样做会相对类似。设置文本当前看起来像这样,但根本不起任何作用

    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有什么区别(很抱歉没有问题)?我刚刚试过,它很有效,你是不是在某个时候写得太多了?@chris
setText
继承自
HasText
,实际上只是将值传递给
setValue
。即使尝试了这一点,日期框也不会显示任何文本。好奇的是,文本框中的setText和setValue有什么区别(很抱歉这个问题)?我刚刚试过,它很有效,你是不是在某个时候写得太多了?@chris
setText
继承自
HasText
,实际上只是将值传递给
setValue