简体   繁体   English

如何从日期列表创建 DatePicker

[英]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 ,其值在morningSloteveningSlot中。 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.

相关问题 如何在 android 日期选择器中突出显示日期? - How to highlight dates in android datepicker? 有两个日期。 如何创建这些日期之间每月间隔的列表? - There are two dates. How to create a list of the intervals of months between these dates? Kotlin:在 for 循环中创建内部类的所有日期列表。 从日期列表中查找最新日期 - Kotlin: create list of all dates from inner classes in for loop. find latest date from the list of dates 如何创建这样的日期选择器? - How to create a datepicker like this? 如何在Android DatePicker中禁用以前的日期? - How to disable previous dates in Android DatePicker? 如何禁用Android Datepicker中的某些特定日期? - how to disable certain specific dates in Android datepicker? 如何使用Selenium和Java从ui-datepicker查找活动日期 - How to find active dates from ui-datepicker using Selenium and Java 如何使用 DatePicker 元素中的日期作为 MPAndroidChart 上的 x 轴值? - How can I use dates from a DatePicker element to be the x-axis values on a MPAndroidChart? 如何从不扩展Activity,Android的类中创建DatePicker? - How to create a DatePicker from class which do not extends Activity, Android? Java-从2个日期开始按月创建日期组 - Java - create group of dates by Month from 2 dates
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM