I'm currently in the process of developing a registration form for my JavaFX application. I am faced with an issue where I need to disable certain cells in the date picker when they do not belong to the displayed month. Let's take a look at my current implementation of the date picker.
Here is my date picker:
https://i.stack.imgur.com/Q4NXs.png
As you can see, I want the dates 27th, 28th, ..., 30th from the current month and the 1st, 2nd, 3rd, ... from the next month to be greyed out. How can I achieve this?
I have explored various methods to implement this functionality, and it seems like it might involve the "dayCellFactory", but I'm not entirely sure...
final Callback<DatePicker, DateCell> dayCellFactory = new Callback<>() {
public DateCell call(DatePicker datePicker) {
return new DateCell() {
@Override
public void updateItem(LocalDate item, boolean empty) {
super.updateItem(item, empty);
this.getStyleClass().add("form-date-picker-cell");
}
};
}
};
datePicker.setDayCellFactory(dayCellFactory);
My initial approach was to retrieve the current month from the date picker and compare each cell against it, but I am unsure how to get the month information from the date picker.