我正在使用CalendarFX框架中的MonthPage,但在将条目添加到MonthPage时遇到问题。下面的代码显示了我添加条目的方式,它不会引发异常,但是并未在用户界面中显示条目。



public void initCalendar() {

        for(Task task : allTasks){
            Entry entry = new Entry(task.getTitle());
            //converting the date to localDate
            Date date = task.getDeadline();
            LocalDate entryDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            x.changeEndDate(entryDate);
            calendar.addEntry(x);
        }

        CalendarSource calendarSourceTasks = new CalendarSource("Tasks");
        calendarSourceTasks.getCalendars().addAll(calendar);

 //Calender and MonthPage is initialized above this method
 monthPage.getCalendarSources().setAll(calendarSourceTasks);


    }

最佳答案

我知道我回答得有点晚了,但也许会对其他人有所帮助。

就我而言,我使用的是DetailledDayView和MonthView,我使用了以下代码:

Calendar calendar = new Calendar("Test");
CalendarSource calendarSource = new CalendarSource("source");
DetailedDayView detailledDayView;

Entry<String> entry = new Entry<>("Hello");
        entry.setInterval(LocalDate.now());
        entry.changeStartDate(LocalDate.now());
        entry.changeEndDate(LocalDate.now());
        entry.changeStartTime(LocalTime.of(12,30));
        entry.changeEndTime(LocalTime.of(13,30));
        calendar.addEntry(entry);

// You do the adding here and the entry will be displayed automatically
calendarSource.getCalendars().addAll(calendar);
detailledDayView.getCalendarSources().setAll(calendarSource);


由于您使用的是MonthPage而不是MonthView,因此必须将最后一行更改为:

monthPage.getMonthView.getCalendarSources().setAll(calendarSourceTasks);


希望我的解决方案对某人有所帮助!
不错的编码:)

09-11 19:59