2016-11-11 76 views

回答

0

你不能做到这一点与此组件。

但是,您可以将它与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; 
    } 

} 
+0

是的,我实际上并最终分别使用3个组合框。谢谢@Krzysztof Majewski –