你不能做到這一點與此組件。
但是,您可以將它與Resolution.DAY
(默認值)一起使用,併爲小時和分鐘選取器生成您自己的組合框。
實施例組分:
public class MyDatePicker extends VerticalLayout {
private InlineDateField dateField;
private NativeSelect hourPicker;
private NativeSelect minutePicker;
public MyDatePicker(String caption) {
setSizeUndefined();
dateField = new InlineDateField(caption);
hourPicker = new NativeSelect();
minutePicker = new NativeSelect();
HorizontalLayout hourLayout = new HorizontalLayout();
hourLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
Label colonLabel = new Label("<b>:</b>");
colonLabel.setContentMode(ContentMode.HTML);
hourLayout.addComponents(hourPicker, colonLabel, minutePicker);
addComponents(dateField, hourLayout);
setComponentAlignment(hourLayout, Alignment.MIDDLE_CENTER);
setValues();
}
private void setValues() {
hourPicker.setContainerDataSource(new BeanItemContainer<>(String.class, new ArrayList<>(Arrays.asList("01", "02", "...", "24"))));
minutePicker.setContainerDataSource(new BeanItemContainer<>(String.class, new ArrayList<>(Arrays.asList("00", "15", "30", "45"))));
hourPicker.select("01");
minutePicker.select("00");
}
public Date getValue() {
Date date = dateField.getValue();
// set hour and minutes to date
return date;
}
}
是的,我實際上並最終分別使用3個組合框。謝謝@Krzysztof Majewski –