GWT DateBox是一个文本字段, 当我们单击内部时会弹出日期选择器。 getValue和setValue方法返回/接受Date对象, 而不是原始String。
GWT DateBox语法
public class DateBox extends Composite
GWT DateBox嵌套类
类 |
描述 |
DateBox.DefaultFormat |
它是默认的DateBox.Format类。 |
DateBox.Format |
它由委托实现, 以处理日期值的解析和格式化。 |
GWT DateBox构造函数
建设者 |
描述 |
DateBox() |
它使用新的DatePicker创建一个日期框。 |
DateBox(DatePicker picker, java.util.Date date, DateBox.Format format) |
它创建一个新的日期框。 |
GWT DateBox常用方法
修饰符和类型 |
方法 |
描述 |
HandlerRegistration |
addValueChangeHandler(ValueChangeHandler <java.util.Date>处理程序) |
它添加一个ValueChangeEvent处理程序。 |
LeafValueEditor <java.util.Date> |
asEditor() |
它返回由DateBox支持的TakesValueEditor。 |
int |
getCursorPos() |
它在日期框中获取当前光标位置。 |
DatePicker |
getDatePicker() |
它获取日期选择器。 |
boolean |
getFireNullValues() |
如果日期框将针对无效或空字符串值使用日期值null触发ValueChangeEvents, 则它返回true。 |
DateBox.Format |
getFormat() |
它获取用于控制此DateBox格式和解析的格式实例。 |
int |
getTabIndex() |
它获取日期框在选项卡索引中的位置。 |
TextBox |
getTextBox() |
它得到文本框。 |
java.util.Date |
getValue() |
它获取显示的日期, 如果文本框为空或无法解释, 则为null。 |
void |
hideDatePicker() |
它隐藏了日期选择器。 |
boolean |
isDatePickerShowing() |
如果当前显示日期选择器, 则返回true, 否则返回false。 |
void |
setAccessKey(char key) |
它设置日期框的“访问密钥”。 |
void |
setFormat(DateBox.Format format) |
它设置用于控制此DateBox中日期的格式和解析的格式。 |
void |
setTabIndex(int index) |
它设置日期框在选项卡索引中的位置。 |
void |
showDatePicker() |
它解析当前日期框的值并显示该日期。 |
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<ComponentEvent>() {
public void handleEvent(ComponentEvent be) {
String d = DateTimeFormat.getShortDateFormat().format(picker.getValue());
Info.display("Date Selected", "You selected {0}.", new Params(d));
}
});
add(picker);
}
}
输出:
评论前必须登录!
注册