private void updateCalendar() {
        LocalDate calDate = currentDate.withDayOfMonth(1).withDayOfWeek(1);
        LocalDate finishDate = currentDate.withDayOfMonth(currentDate.dayOfMonth().getMaximumValue()).withDayOfWeek(7);
        if (currentDate.getDayOfWeek() <= 6) {
            //add extra week for when the date falls on a sunday.
            finishDate = finishDate.plusWeeks(1);
        }
        Button button = null;
        int x = 0, y = 0;
        monthLabel.setText(currentDate.monthOfYear().getAsText());
        while (calDate.compareTo(finishDate) <= 0) {
            String id = "#grid" + Integer.toString(y) + Integer.toString(x);
            button = (Button) lookup(id);
            button.setText(Integer.toString(calDate.getDayOfMonth()));
            button.getStyleClass().clear();
            button.setUserData(calDate);
            button.getStyleClass().add("button");
            button.getStyleClass().add("datepicker-day");
            button.setOnAction(new EventHandler() {
                @Override
                public void handle(Event t) {
                    if (selectedButton != null) {
                        selectedButton.getStyleClass().remove("datepicker-selected");
                    }
                    Button source = (Button) t.getSource();
                    source.getStyleClass().add("datepicker-selected");
                    selectedButton = source;
                    selectedDate = (LocalDate) source.getUserData();
                    if (dateHandler != null) {
                        dateHandler.handle(t);
                    }
                }
            });
            if (calDate.getMonthOfYear() != currentDate.getMonthOfYear()) {
                button.getStyleClass().add("datepicker-other");
            }
            if (calDate.compareTo(date) == 0) {
                button.getStyleClass().add("datepicker-today");
            }
            calDate = calDate.plusDays(1);
            if (x == 6) {
                y += 1;
                x = 0;
            } else {
                x += 1;
            }

        }

    }