[英]How to create a DatePicker from a List of dates
I am learning JavaFX and came across a requirement in my JavaFX application where I want to create a Datepicker using an ArrayList
of dates.我正在学习 JavaFX 并在我的 JavaFX 应用程序中遇到了一个要求,我想使用
ArrayList
的日期创建一个 Datepicker。 I need to disable all other dates which are not present in this list (dateList).我需要禁用此列表 (dateList) 中不存在的所有其他日期。 Finally, according to the date selected, I need to render a
ComboBox
with values in morningSlot
and eveningSlot
.最后,根据选择的日期,我需要渲染一个
ComboBox
,其值在morningSlot
和eveningSlot
中。 The structure of the object is as follows. object的结构如下。
Schedule {
List<LocalDate> dateList;
String morningSlot;
String eveningSlot;
}
Solved the same using the below code.使用下面的代码解决了同样的问题。 Thanks VGR for the input.
感谢 VGR 的输入。
final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
@Override
public DateCell call(final DatePicker datePicker)
{
return new DateCell() {
@Override
public void updateItem(LocalDate item, boolean empty)
{
super.updateItem(item, empty);
setDisable(empty || !dateList.contains(item));
}
};
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.