只需將clickhandler添加到將日期選擇器設置爲可見的圖像即可。
它會成爲這樣的事情:
private DatePicker datePicker = new DatePicker();
private TextBox textBox = new TextBox();
private Image icon = new Image("calendar.png");
public void onModuleLoad() {
datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
@Override
public void onValueChange(ValueChangeEvent<Date> event) {
Date date = event.getValue();
String dateStr = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM).format(date);
textBox.setText(dateStr);
datePicker.setVisible(false);
}
});
datePicker.setVisible(false);
icon.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
datePicker.setVisible(true);
}
});
RootPanel.get().add(icon);
RootPanel.get().add(textBox);
RootPanel.get().add(datePicker);
}
大 - 謝謝!我用datePicker.showDatePicker()代替了datePicker.getDatePicker()。setVisible(true),它工作得很好。謝謝! – jcovert 2011-04-21 14:53:13
很高興幫助你。 – 2011-04-21 14:55:58