📜  GWT DateBox

📅  最后修改于: 2021-01-02 12:42:00             🧑  作者: Mango

GWT日期框

GWT DateBox是一个文本字段,当我们单击内部时会弹出日期选择器。 getValue和setValue方法返回/接受Date对象,而不是原始String。

GWT DateBox语法

public class DateBox extends Composite

GWT DateBox嵌套类

Class Description
DateBox.DefaultFormat It is the default DateBox.Format class.
DateBox.Format It is implemented by a delegate to handle the parsing and formatting of date values.

GWT DateBox构造函数

Constructor Description
DateBox() It creates a date box with a new DatePicker.
DateBox(DatePicker picker, java.util.Date date, DateBox.Format format) It creates a new date box.

GWT DateBox常用方法

Modifier and types Methods Description
HandlerRegistration addValueChangeHandler(ValueChangeHandler handler) It adds a ValueChangeEvent handler.
LeafValueEditor asEditor() It returns a TakesValueEditor backed by the DateBox.
int getCursorPos() It gets the current cursor position in the date box.
DatePicker getDatePicker() It gets the date picker.
boolean getFireNullValues() It returns true iff the date box will fire ValueChangeEvents with a date value of null for invalid or empty string values.
DateBox.Format getFormat() It gets the format instance used to control formatting and parsing of this DateBox.
int getTabIndex() It gets the date box’s position in the tab index.
TextBox getTextBox() It get text box.
java.util.Date getValue() It get the date displayed, or null if the text box is empty, or cannot be interpreted.
void hideDatePicker() It hide the date picker.
boolean isDatePickerShowing() It returns true if date picker is currently showing, false if not.
void setAccessKey(char key) It sets the date box’s ‘access key’.
void setFormat(DateBox.Format format) It sets the format used to control formatting and parsing of dates in this DateBox.
void setTabIndex(int index) It sets the date box’s position in the tab index.
void showDatePicker() It parses the current date box’s value and shows that date.

GWT DateBox示例

import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.util.Params;
import com.extjs.gxt.ui.client.widget.DatePicker;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;

public class Hello implements EntryPoint {
  public void onModuleLoad() {
    RootPanel.get().add(new DatePickerExample());
  }
}
class DatePickerExample extends LayoutContainer {

  @Override
  protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    setLayout(new FlowLayout(10));
    final DatePicker picker = new DatePicker();
    picker.addListener(Events.Select, new Listener() {

      public void handleEvent(ComponentEvent be) {
        String d = DateTimeFormat.getShortDateFormat().format(picker.getValue());
        Info.display("Date Selected", "You selected {0}.", new Params(d));
      }

    });
    add(picker);
  }

}

输出: